问题
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