0
How do I make an integer appear in a string
Okay, I'm trying to write a program that will take the age in integer but print the answer in a sentence. Like when I ask the question, 'how old are you', I get a prompt to input my age in years, convert it by multiplying by 365 days to get the result in days and , then I want to print the response in a sentence. Like 'You are 5500 days old. This is the program I wrote: x = input("How old are you: ") Age = int(x) y = (x * 365) print("You are y days old) I'm not getting the right answer, please help.
9 Réponses
+ 1
in python u can use format specifiers...eg.,
age = 10
print("Age is %d"%age)
output:
Age is 10
0
print ("you are %d days old" % (y))
let me know if it doesn't work
0
Raj, it didn't work, there's an error saying that 'a number is required not string'
0
let me check it on playground
0
ah! my bad, I didn't notice.
mention int in input else it will take input as string
do x=int (input ("enter age: "))
and print ("your age %d days" %(y))
it will work now
0
you did type conversion later. ..but multiplied with x, not with age...that's problem
0
That's good! Thanks Raj it work! Cheers
0
cheers. ..good night :)
0
age=10
print("Your Age Is " + str(age))
number=50
number=str(number)
print("Your number is " + number)