I've been using a code for awhile trying to get text and variables in the same line to print a sentence that depends mainly changing variables based on int(inuput) it doesn't work
Like this?
a = int(input("Enter a large number"))
b = a + 1
print("Okay thats pretty large but {} is larger".format(b))
@BlueLightning42
a = int(input())
b = (a - 1 )
c = (a + 1)
d = ("The next number for the number ")
e = ("is ")
f = ("The previous number for the number ")
print(d + a + e + b )
I did it in this format, but I don't exactly know how to fix it
@KrystanKlukos just so you know
if your repl is python 3 (not python 2) and cause print is a function in python 3 you could also pass multiple parameters to it/ write something like this
a = int(input())
b = a - 1
c = a + 1
d = "The next number for the number "
e = "is "
f = "The previous number for the number "
print(d, a, e , b, f , c)
using format is the prefered way of going about it
Can u provide an example or a repl link please?
@leon332157 a = int(input())
b = (a - 1 )
c = (a + 1)
d = ("The next number for the number ")
e = ("is ")
f = ("The previous number for the number ")
print(d + a + e + b )
@KrystanKlukos Ok, so first of all, (a-1) is a tuple which contains integer a-1, assigned to b, same for c, and d and e is a tuple with string in it, so if you call print function with these data type, it will not work.
@KrystanKlukos a = int(input())
b = a - 1
c = a + 1
d = "The next number for the number "
e = "is "
f = "The previous number for the number "
print('{}{}{}{}'.format(d, a ,e , b ))
@KrystanKlukos And this is also a Python basics, I would suggest you to review data types, operations, input and print functions. :)
@leon332157 beat me by a few seconds but kudos
@BlueLightning42 What is that for? We always help ppl ;)
@leon332157 Thank you
@BlueLightning42 Both of you are appreciated haha
You could convert the integers/floats into strings via the str() method.
a = int(input("Enter Some Number"))
b = a + 1
print("New Number = " + str(b))