jetbrians: stage 3 project

python : jetbrains project stage 3
my code in

min_water = 200
min_milk = 50
min_coffee_beans = 15
machine_water = int(input())
machine_milk = int(input())
machine_coffee_beans =int(input())
coffee_need_cups = int(input())
water = machine_water // min_water
milk = machine_milk // min_milk
beans = machine_coffee_beans // min_coffee_beans
min_cups = min(beans, milk, water)

if coffee_need_cups == min_cups:
    print("Yes, I can make that amount of coffee")
elif coffee_need_cups < min_cups:
    N = min_cups - coffee_need_cups
    print("Yes, I can make that amount of coffee (and even ", N, "more than that)")
elif coffee_need_cups > min_cups:
    print("No, I can make only ", min_cups, "cups of coffee")

to improve it :

if cup == minimum_cup:
  print("Yes, I can make that amount of coffee")
elif cup > minimum_cup:
  print("No, I can make only", minimum_cup, "cups of coffee")
else:    
  print("Yes, I can make that amount of coffee (and even", minimum_cup - cup, "more than that") 

other solution

print('Write how many ml of water the coffee machine has:\n> ')
available_water = int(input().strip())

print('Write how many ml of milk the coffee machine has:\n> ')
available_milk = int(input().strip())

print('Write how many grams of coffee beans the coffee machine has:\n> ')
available_coffee_beans = int(input().strip())

print('Write how many cups of coffee you will need:\n> ')
target_cups_of_coffee = int(input().strip())

water_per_cup = 200
milk_per_cup = 50
coffee_beans_per_cup = 15

cups_of_water = available_water // water_per_cup
cups_of_milk = available_milk // milk_per_cup
cups_of_coffee_beans = available_coffee_beans // coffee_beans_per_cup

max_cups = min(cups_of_water, cups_of_milk, cups_of_coffee_beans)

if max_cups >= target_cups_of_coffee:
    print("Yes, I can make that amount of coffee", end=None)
    if max_cups > target_cups_of_coffee:
        print(" (and even" + str(max_cups - target_cups_of_coffee) + " more than that)")
else:
    print("No, I can only make " + str(max_cups) + " cups of coffee")

注意点:
print(",…")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值