问题是:
Give numBottles(input) full water bottles, you can exchange numExchange(input) empty bottles for one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Return the maximum number of water bottles you can drink. No functions, imports, whatsoever, only list, string, int, loops and that kinda stuff.
Ex.1:
Input(s): numBottles = 9, numExchange = 3 Output: 13 Explanation: You can exchange 3 empty bottles to get 1 full water bottle. Number of water bottles you can drink: 9+3+1 = 13
Ex.2: Input(s) :numbottles = 15, numexchange = 4 Output: 19 Explanation: You can exchange 4 empty bottles to get 1 full water bottle. Number of water bottles you can drink: 15 + 3 + 1 = 19
我得到的是:
Numbottles = int(input("Numbottles"))
Numexchange = int(input("NumExchange"))
total = []
for i in range(0,Numbottles // Numexchange):
x = Numbottles % Numexchange
total.append(x)
print(sum(total))
请试试这个
相关问题 更多 >
编程相关推荐