我正在編寫基於巧克力數學遊戲的代碼(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