0

String formating Inserting spaces

Can someone help me insert spaces, please....(the output is Nameisageyears old?)i/o Name is age years old... name = input() age = int(input()) #your code goes here print("{0}{1}{2}{3}".format(name ,"is", age ,"years old"))

22nd Feb 2022, 9:28 PM
Cathyboum
4 Answers
+ 1
# if you want to insert spaces, better use fstrings: print(f'{name} is {age} yo') # or your way: print('{0} is {1} yo'.format(name,age)) # or ...: print('%s is %d yo'%(name,age))
22nd Feb 2022, 9:44 PM
Ervis Meta
Ervis Meta - avatar
0
What have you tried? Does your "is" output all the characters between the quotation marks? What if you changed that to "is or is not"? Would all of the characters be printed (including the spaces)?
22nd Feb 2022, 9:44 PM
HungryTradie
HungryTradie - avatar
0
You got it right just keep the name and age as format and keep {0} and {1} add a space between the 0 and 1 and put is. Then at the end of {1} add another space then years old
22nd Feb 2022, 10:24 PM
Ion Kare
Ion Kare - avatar
0
Thank you for all the feedback...it worked! name = input() age = int(input()) #your code goes here a="{} is {} years old".format(name,age) print(a)
23rd Feb 2022, 11:03 AM
Cathyboum