Coke Machine -Problem Set 2 (CS50's Introduction to Programming with Python)

preview_player
Показать описание
hello, everyone, and welcome to another video, in this video, I will explain and solve problem set 2, Coke Machine.

Don't forget to hit the like button and subscribe to the channel, and if you have any questions or want an explanation for a specific problem leave a comment down below.

Рекомендации по теме
Комментарии
Автор

In line 15 (change owed)Not true (Change Owed)That's right, you must write the first letters in capitals, otherwise you will encounter two bugs❤️ Please always try check50 before finishing the video so that others who are new comers don't face problems:)

maede
Автор

if you haven't already submitted this problem, You have to try this on your own.
This video is to just give you a way to solve this problem, try solving it using a different approach, to get the most benefits out of this experience.

TheCodingCreator
Автор

I did it this way:

i = 50
while i > 0:
print("Amount Due:", i)
coin = int(input("Insert coin: "))
if coin == 25 or coin == 10 or coin == 5:
i -= coin
print("Change Owed:", -i)

krzysztofnowicki
Автор

Thankss sooo much, this video helped me see what was wrong with my code. I had print("Amount Due: 50") for lines 12 and 18 and I had print("Change Owed:", total_coins - 50) for line 15. All I had to do was use the f string. Thanks againnn

Thomdloi
Автор

Thanks. Mine below looks few steps longer. may be I need to simplify it?

coins = [25, 10, 5]
due = 50

while due > 0:
m = int(input("Insert Coin: "))
if m in coins:
due = due - m
if due > 0:
print("Amount Due: ", due)
else:
print("Change Owed: ", abs(due))

else:
print("Amount Due: ", due)

getstart
Автор

I tried it this way:
amount_due = 50
print("amount due:", amount_due)

insert = int(input("Insert Coin: "))
coin = amount_due - insert
while True:
if coin > 0:
print("Amount due:", coin)
insert = int(input("Insert coin: "))
coin = coin - insert
continue
else:
print("Amount due:", coin)
break

Improvewithchiya
Автор

Thanks, i did this, but it isn't accepted by the check50 command...

x = 50
print(f"Amount Due:{x}")
while True:
value = int(input("Insert Coin:"))
if value == 25 or value == 10 or value == 5 :
if value > x :
x = value - x
print(f"Changed Owed:{x}")
break
else:
x = x - value
if x <= 0:
print(f"Changed Owed:{x}")
break
else:
print(f"Amount Due:{x}")
else:
print(f"Amount Due:{x}")
continue

yuuPuck
Автор

uhh, for some reason I did this

due_money = 50
enter_coin = 0
print("Amount Due: ", due_money)

while True:
clickin = input("insert coin: ")
if clickin in [25, 10, 5]:
due_money -= clickin
enter_coin += clickin
else:
print(f"Amount Due: {due_money}")

if enter_coin >= 50:
print(f"Change owed: {enter_coin - 50}")
break

else:
print(f"Amonut Due: {due_money}")

for some reason it says that break must be in while loop, but it is in the while loop and when I don't have it, the insert coin would continue after submitting:
Amount Due: 50
insert coin: 25
insert coin: 15
insert coin: 10
insert coin: 5
insert coin:

jbbiron
Автор

Yeah I followed along & it doesnt work as it did for you

print("Amount Due: 50")

amount_due = 50
coins_added = 0

while True:
insert_coin = int(input("Insert Coin: "))
if insert_coin == 5 or insert_coin == 10 or insert_coin == 25:
amount_due -= coins_added
coins_added += insert_coin

if coins_added >= 50:
print(f"Change Owed: {coins_added - 50}")
break
else:
print(f"Amount Due: {amount_due}")

roshansingh
Автор

mine was pretty long lol
ammountdue = 50
print("Amount Due:", ammountdue)
total = 0
while ammountdue > 0:
user = input("Insert Coin: ")
coin = int(user)
if coin == 25:
ammountdue = ammountdue - coin
total = total + coin
if total < 50:
print("Amount Due:", ammountdue)
else:
break
elif coin == 10:
ammountdue = ammountdue - coin
total = total + coin
if total < 50:
print("Amount Due:", ammountdue)
else:
break
elif coin == 5:
ammountdue = ammountdue - coin
total = total + coin
if total < 50:
print("Amount Due:", ammountdue)
else:
break
else:
print("Amount Due:", ammountdue)
continue
print("Change Owed:", total - 50)

kayladew
Автор

i did this way
i=50
while i>0:
print("Amount Due:", i)
coin=int(input("Insert Coin:"))

if coin not in [5, 10, 25]:
print("Please insert coins of 5, 10, or 25!")

if coin==5 or coin==10 or coin==25:
i=i-coin

print("Change Owed:", i)

ClipoMeter
join shbcf.ru