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
5 Answers
+ 1
print("{} is {} years old".format(name, age))
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")
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.
0
Learn about formatting strings
name='James'
age=42
print (f'{name} is {age} years old')
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.