Basic variables problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic variables problem

Can't get variables to work with strings. I need to output "James is 42 years old", the variables are; name = James, age = 42. I have tried print("name is age years old") but the variables don't work with this. Any help is much appreciated. Thanks

26th Sep 2021, 10:37 PM
Adam
5 Answers
+ 1
print("{} is {} years old".format(name, age))
27th Sep 2021, 12:37 AM
Honorable Con 🇸🇳
Honorable Con 🇸🇳 - avatar
0
I think you need this: Print(f"{name} is {age} years old") Or you can use the old way: Print(name + " is " + str(age) + " years old")
27th Sep 2021, 12:25 AM
Abdelrahman Tlayjeh
0
Thanks for your suggestion, it is still not working unfortunately. I think perhaps coding is too difficult for me to comprehend, I might call it a day.
27th Sep 2021, 3:09 AM
Adam
0
Learn about formatting strings name='James' age=42 print (f'{name} is {age} years old')
27th Sep 2021, 4:55 AM
Prabhas Koya
0
Thank you both for your help, there was no information about {} or using f in the code on sololearn. Without your help I would not have solved the problem. This makes me question the merits of sololearn.
27th Sep 2021, 9:52 AM
Adam