0
name = 'James' age = 34 print("name is age years old")
What am I doing wrong here I want the output to be “James is 34 years old” but the output becomes “name is age years old
28 Answers
+ 15
print (name, " is ", age, " years old")
+ 7
You should write variable name outside the inverted comma's
+ 6
Okkay, so what you were doing wrong is -->
Basically python think a bunch or letter/number/anything in the Quotation marks (") as Strings (str). Now, if you print a str or string, the whole string will be printed.
On the other hand, variables do not have the Quotation marks. So, in a print, if you want to refer to a variable, you must use its name outside the Quotation marks. And to separate the strings and variables, commas (,) are used.
Hope you got the point and Best of Luck <3
+ 5
I have already answered
+ 4
do this code -->
name = 'James'
age = 34
print(name, " is ", age, " years old.")
---------------------------------------
You may also do this -->
print("{name} is {age} years old".format(name = "Jamse", age = 34))
---------------------------------------
Also -->
name = "James"
age = 34
print(f"{name} is {age} years old.")
-----------------------------------
Btw, the first one is better for you, I guess...
+ 2
That easy 😉
Name = "James"
Age = 34
print (Name, " is ", Age, " years old")
+ 1
Try this:
print(name , " is ", age , " years old")
As you write it now, you are printing the string "name is age years old" and you are not actually using the variables created by you(name and age)
+ 1
Read the lessons about variables and you will understand a lot easier.
+ 1
You are welcome, Dima Melnichuk.
Good luck learning Python...
+ 1
Dima Melnichuk
Variables:
name = "James"
age = 34
Examples:
print(name , "is" , age , "years old")
print(f"{name} is {age} years old")
print("{} is {} years old".format(name, age))
print("%s is %s years old"%(name, age))
+ 1
Try using f strings.
name = ‘James’
age = 34
print(f‘{name} is {age} years old’)
+ 1
https://code.sololearn.com/c74DqM1B93BM
name ='James'
age=34
print('%s is %i year old'%(name,age))
print("{} is {} years old".format(name,age))
+ 1
name = input()
age = input()
print(name, " is ", age, " years old.")
+ 1
Name="james"
Age=34
Print(name+" is"+ age+" years old")
+ 1
If u do it with c++ :
cout << name << "is " << age << "years old\n";
C :
printf("%s is %d years old\n", name, age);
Python :
print(name, "is", age, "years old")
This may help you ☺️
+ 1
Because age and name both are in String it should be like this print(name + " is " + age + "year old");
+ 1
print("my name is james and I am "+ str(age) +"years old.")
0
So what was i doing wrong in the code was i not adding thr commas? Or the quotes
0
And what does that look like because i started coding yesterday
0
Ooo i get what i did wrong i put in “name not name