26th Jun 2017, 6:38 AM
shaurya vatshal
shaurya vatshal - avatar
6 Respuestas
+ 1
or better style maybe would be: print ("hello\n welcome to my code!...") age=input() print ("you are of="+age+"years") age=int(age) x= 2017-age print (x) (I'm sorry, I'm not this good in Python 🙈)
26th Jun 2017, 7:01 AM
Mo Jakobi
Mo Jakobi - avatar
+ 1
print ("hello\n welcome to my code!\nplease enter your age") age=int(input()) agestr=str(age) print ("you are of="+agestr+"years") x = 2017-age print (x)
26th Jun 2017, 6:58 AM
Mo Jakobi
Mo Jakobi - avatar
+ 1
it's a useless extra variable, as you can see in my second answer, it's omittable. Anyways, Python auto-converts to the mostfitting data types automatically most of the time, but it seems to be hard to change back from string and also to string, if you hard cast it to be integer. that's why i used the extra variable. But if you cast after printing the String (or adding up to a return string), you don't need the other variable.
26th Jun 2017, 7:06 AM
Mo Jakobi
Mo Jakobi - avatar
+ 1
thanks
26th Jun 2017, 7:07 AM
shaurya vatshal
shaurya vatshal - avatar
0
thanks jakobi
26th Jun 2017, 7:02 AM
shaurya vatshal
shaurya vatshal - avatar
0
what is that agestr in your code
26th Jun 2017, 7:02 AM
shaurya vatshal
shaurya vatshal - avatar