How to add on python [closed]

余生颓废 提交于 2019-12-04 07:14:26

问题


I am trying to make a program where I can ask someone's age - then tell them that on their next birthday they will be x many years old.

for example:

python = "How old are you?"
answer = "17"

python = "On your next birthday you will be 18 years old".

that is the program which I am trying to make however I am stuck on how to add 1 to the age of the person


回答1:


How about this?

age += 1

or

age = age + 1

Make sure you are casting the user's input from a string to an integer.




回答2:


In order to increase age by one, you need it to be an integer. Try:

age = int(input("How old are you? ")
age += 1
print("On your next birthday you will be" + str(age) + "years old")



回答3:


age = input('How old are you?')
print('On your next birthday you will be' + str(int(age)+1) + 'years old.')


来源:https://stackoverflow.com/questions/22079657/how-to-add-on-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!