-
-
Save aesophor/4a3a6f02984df3300318de70e324593a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- encoding: utf-8 -*- | |
def get_total(x, y, z): | |
return 25 * x + 30 * y + 20 * z | |
def get_leftover(money, x, y, z): | |
return money - get_total(x, y, z) | |
def maybe_show(money, x, y, z): | |
leftover = get_leftover(money, x, y, z) | |
if leftover >= 0 and (x > 0 or y > 0 or z > 0): | |
str = '' | |
str += '橘子{}斤'.format(x) if x > 0 else '' | |
str += '火龍果{}顆'.format(y) if y > 0 else '' | |
str += '木瓜{}顆'.format(z) if z > 0 else '' | |
str += '剩{}元'.format(leftover) if leftover > 0 else '' | |
print(str) | |
def main(): | |
money = int(input('請輸入餘額:')) | |
x = 0 | |
y = 0 | |
z = 0 | |
while get_total(x, y, z) <= money: | |
while get_total(x, y, z) <= money: | |
while get_total(x, y, z) <= money: | |
maybe_show(money, x, y, z) | |
z += 1 | |
maybe_show(money, x, y, z) | |
z = 0 | |
y += 1 | |
maybe_show(money, x, y, z) | |
y = 0 | |
x += 1 | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment