+ 2
How do I produce "John is 20 years old" as output given the variables name="John" age="20"?
Contact management system
14 Answers
+ 5
name="John"
age="20"
print(name + 'is' + age 'years old')
#myattempt
+ 4
ㅤㅤㅤ 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 :)
+ 4
Use format string formate
Example code
name = "John"
age = 20
print(f"{name} is {age} year old")
+ 3
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
+ 3
Thanks everyone name, age = input(), int(input())
print(f'{name} is {age} years old') went through
+ 1
name, age = input(), int(input())
print(f'{name} is {age} years old')
+ 1
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
+ 1
Print(name+"is"+age+"years old")
+ 1
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 { }!
0
Please show your attempt first.
0
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 :)
0
name = "John"
age = "20"
print(f"{name} is {age} years old")
0
name = "John"
age = "20"
print(name + "is" + age + "years old")