我正在编写基于巧克力数学游戏的代码(http://www.joe-ks.com/Chocolate_Math.htm)。我可以让代码运行良好,除了最后一部分。Python将3位数字分成两部分
我希望输出结果是可读的,例如,“您的最终数字是533.这意味着您的原始数字是5,您的年龄是33岁。”
我无法弄清楚的是如何只打印三位数字的最后两位数字。
orig_num = int(input("Okay, tell me how many times a week you want chocolate. It should be more than one, but less than 10: "))
guess = ((orig_num * 2) + 5) * 50
birthday = input("Have you had your birthday this year? Y/N: ")
if birthday == 'Y':
guessb = guess + current_year - 250
elif birthday == 'N':
guessb = guess + current_year - 251
year = int(input("What year were you born? (Don't worry, I won't look): "))
less_year = guessb - year
print("Well! Your number is {}. That means your original number was {}, and you are {} years old".format(less_year, orig_num, less_year))
我感觉好像我应该在这里某个地方有一个功能,但我太绿了,不知道在哪里。
模量工作!非常感谢你。 – mimc83