- 3
name = input() age = input() print(name + " is " + age)
Why this code resulting error plz help anyone
27 Answers
+ 4
Calvin Thomas
Yes that will also work but print statement is already given in practice code.
We just have to change Hard Code input to user input.
+ 4
The code is correct but when you give the input, do it on different lines. Eg. On the first line write the name and then on the second line write the age.
+ 2
Your name in first line and your age in 2nd line
+ 2
Your code is correct friend,
I think your complier may have some error, just update it.
+ 2
Mohammad Hasan no, even if age is a number, we can still store it as a string. Remember '0', '1', etc are characters; only 0,1,etc are numbers
+ 2
Rishi
I've already forgotten that:(
(I started learning again today)thanks for telling me my mistake:)
+ 2
just remove double quotes from is and place it in starting and ending of brackets but place it inside and at last do semicolon after the bracket is closed
+ 2
There a many ways of formating text in python , they include the following
print(f"{name} is {age})
print(" {} is {}".format(name, age))
print(" %s is %d"%(name, age))
+ 2
Guys his code is write just output is incomplete.
It's a problem of practice 17.2 in Python For Beginners course.
+ 2
There are not problem with formatting,
Akash Kumar
Here is answer on your question
You should split multiple input into separate lines
Please like if it helps 🙂
https://ibb.co/vx9L4gK
https://ibb.co/QQpzrfG
Ash wrote:
The code is correct but when you give the input, do it on different lines. Eg. On the first line write the name and then on the second line write the age.
👍
+ 2
It will give Syntax eror.
+ 2
I mean it will give Syntax eror
+ 2
Form my view
+ 2
correction
age=int(input())
and on a second line
+ 1
Akash Kumar
Your code is write but I think you didn't check problem statement properly.
Your output should be this:
print(name + " is "+age+" years old")
+ 1
Thanks Atul
+ 1
This also works:
print(name, "is", age, "years old")
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Oh, didn't quite realize that. Thanks for the correction.
+ 1
The code works try using another compiler, or try using string concantination,
Im not really sure of the syntax(not a pythonista) but you can check it out
+ 1
Use the format method, it is usefull in these cases