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

11th Sep 2021, 12:31 PM
Dima Melnichuk
28 odpowiedzi
+ 15
print (name, " is ", age, " years old")
11th Sep 2021, 12:35 PM
Prerna 💞
+ 7
You should write variable name outside the inverted comma's
11th Sep 2021, 12:41 PM
Prerna 💞
+ 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
11th Sep 2021, 12:46 PM
Tanvir Salehin
Tanvir Salehin - avatar
+ 5
I have already answered
11th Sep 2021, 12:42 PM
Prerna 💞
+ 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...
11th Sep 2021, 12:37 PM
Tanvir Salehin
Tanvir Salehin - avatar
+ 2
That easy 😉 Name = "James" Age = 34 print (Name, " is ", Age, " years old")
11th Sep 2021, 3:42 PM
Vladislav3000 ᕦ(ò_óˇ)ᕤ
Vladislav3000 ᕦ(ò_óˇ)ᕤ - avatar
+ 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)
11th Sep 2021, 12:33 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 1
Read the lessons about variables and you will understand a lot easier.
11th Sep 2021, 12:44 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
+ 1
You are welcome, Dima Melnichuk. Good luck learning Python...
11th Sep 2021, 12:49 PM
Tanvir Salehin
Tanvir Salehin - avatar
+ 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))
11th Sep 2021, 3:30 PM
CGO!
CGO! - avatar
+ 1
Try using f strings. name = ‘James’ age = 34 print(f‘{name} is {age} years old’)
12th Sep 2021, 1:11 AM
Denzel Hooke
Denzel Hooke - avatar
+ 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))
12th Sep 2021, 6:12 AM
Abhishek Kumar
Abhishek Kumar - avatar
+ 1
name = input() age = input() print(name, " is ", age, " years old.")
12th Sep 2021, 6:28 AM
ULLAS R K
ULLAS R K - avatar
+ 1
Name="james" Age=34 Print(name+" is"+ age+" years old")
12th Sep 2021, 6:40 AM
Arun Yadav
+ 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 ☺️
12th Sep 2021, 11:47 AM
GURURAJ KL
GURURAJ KL - avatar
+ 1
Because age and name both are in String it should be like this print(name + " is " + age + "year old");
12th Sep 2021, 3:04 PM
Deepika Singh
Deepika Singh - avatar
+ 1
print("my name is james and I am "+ str(age) +"years old.")
13th Sep 2021, 7:26 AM
Joey Gastusfon
Joey Gastusfon - avatar
0
So what was i doing wrong in the code was i not adding thr commas? Or the quotes
11th Sep 2021, 12:39 PM
Dima Melnichuk
0
And what does that look like because i started coding yesterday
11th Sep 2021, 12:42 PM
Dima Melnichuk
0
Ooo i get what i did wrong i put in “name not name
11th Sep 2021, 12:44 PM
Dima Melnichuk