14 Answers
New Answer1/21/2022 1:00:12 PM
Abraham Zimba14 Answers
New Answerㅤㅤㅤ i don‘t see why age should here be an integer variable (maybe will be it tested in the SL challange) because only for printing this is in my opinion not needed, and you have nothing here to calculate :)
Use format string formate Example code name = "John" age = 20 print(f"{name} is {age} year old")
This is already good, only you need to add one + after age and inputs as follows: name=input() #"John" age=input() #"20" print(name + ' is ' + age + ' years old') #my input here on SL Playground (all inputs at the start) #John #20 # but without # sharp
Thanks everyone name, age = input(), int(input()) print(f'{name} is {age} years old') went through
Hello, Abraham Zimba. I think this should be solved the way many people are suggesting in the comments. The solution should be as follows: name = input () age = input() print(name + ' is ' + age + ' years old') I think that should be enough. Have you tried it? Remember that "+" can be used to concatenate strings. Also, note that i wrote ' is ' instead of 'is', and ' years old' instead of 'years old' (note the empty spaces). I guess that if the code inside of "print" was 'is' and 'years old' instead, the output would be 'Johnis22years old", which is not desirable (no spaces between most of the words) XOXO Nicolás
If you are using Python 3.6 or newer, you can use formatted strings like so: print(f'{name} is {age} years old) Just put an F before the string, type it out normally and surround any variables with { }!
print(input(), 'is', int(input()), 'years old') #one-liner But you can refer to @JaScript if you want to take name and age as variables. edit]: eh! there is a error in your code JaScript: take age as int not as string :)
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message