What is wrong with my python code , | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 )

12th Feb 2022, 9:12 PM
Dzhalil Tilov
13 Answers
+ 7
Remove the blank spaces inside the {}
12th Feb 2022, 9:19 PM
Lisa
Lisa - avatar
+ 4
name = input() age = int(input()) syr = "{0}{1}{2}{3}". format( name, " is " , age ," years old " ) print( syr )
12th Feb 2022, 9:22 PM
Jayakrishna 🇮🇳
+ 4
Dzhalil Tilov I like this way a simple way name = input() age = int(input()) print (name, 'is', age, 'years old')
13th Feb 2022, 4:16 AM
A͢J
A͢J - avatar
+ 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 " )
12th Feb 2022, 9:19 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
Thanks a lot ! Everyone helped me
12th Feb 2022, 9:24 PM
Dzhalil Tilov
+ 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}")
12th Feb 2022, 9:33 PM
Ashan Maduranga
Ashan Maduranga - avatar
+ 1
It's intresting . Thank you , I don't now this
12th Feb 2022, 9:35 PM
Dzhalil Tilov
+ 1
Hi
14th Feb 2022, 1:23 PM
Gul Yousuf
Gul Yousuf - avatar
+ 1
Help
14th Feb 2022, 1:24 PM
Gul Yousuf
Gul Yousuf - avatar
+ 1
Python be like: yeah, we don't have semicolons but we do Indentations in here. And you should remove 2,3.
14th Feb 2022, 5:57 PM
Noman Iqbal
Noman Iqbal - avatar
0
I tried it. But I wanted to understand the mechanics of the first method
13th Feb 2022, 7:38 AM
Dzhalil Tilov
0
Gul Yousuf What help? Ask with separate question.
14th Feb 2022, 2:34 PM
A͢J
A͢J - avatar
- 1
Why not use fstrings? Example : print(f"x - {x} y - {y} z -{z}")
15th Feb 2022, 11:58 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar