+ 5
What is wrong with my python code ,
Hy .My task was to get the name and age and write " Name + " is " + age + " years old " " but something went wrong . My code : name = input() age = int(input()) syr = " { 0} { 1} { 2 } { 3}" .format ( name , "is " , age , " years old " ) print ( syr )
14 Answers
+ 7
Remove the blank spaces inside the {}
+ 4
name = input()
age = int(input())
syr = "{0}{1}{2}{3}". format( name, " is " , age ," years old " )
print( syr )
+ 4
Dzhalil Tilov
I like this way a simple way
name = input()
age = int(input())
print (name, 'is', age, 'years old')
+ 3
the correct format is :
syr = " {0} is {1} years old" .format ( name , age )
or
syr = "{0} {1} {2} {3}" .format ( name , "is " , age , " years old " )
+ 2
Thanks a lot ! Everyone helped me
+ 2
You can also use f string in python...
I'm not sure weather you can do it on sololearn..ā¤ļø
Example
name = "sololearn"
print("Hello {0}".format(name))
Can also be done as below...
name = "sololearn"
print(f"Hello {name}")
+ 1
It's intresting . Thank you , I don't now this
+ 1
Hi
+ 1
Help
+ 1
Python be like: yeah, we don't have semicolons but we do Indentations in here.
And you should remove 2,3.
0
I tried it. But I wanted to understand the mechanics of the first method
0
Gul Yousuf
What help?
Ask with separate question.
- 1
Why not use fstrings?
Example :
print(f"x - {x} y - {y} z -{z}")