Skip to content

Instantly share code, notes, and snippets.

@aesophor
Created April 22, 2021 03:36
Show Gist options
  • Save aesophor/4a3a6f02984df3300318de70e324593a to your computer and use it in GitHub Desktop.
Save aesophor/4a3a6f02984df3300318de70e324593a to your computer and use it in GitHub Desktop.
#!/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