I Haz Codes

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Menu
Vending machine

The code below is for a simple vending machine. Each item in the list represents a coin. If the coins 20p, 50p and two £1 coins were added, the list would be

coins = [20,50,100,100,0,0,0,0,0,0]

Change the code below –

  • change coins so it has 5 coins in it. A 50p, two 10p, a 2p and a 1p.
  • change x to be the first position of the list.
  • Change the while loop so the condition is less than the length of the list.
  • change the last ????? so it adds one to x.
coins = [0,0,0,0,0,0,0,0,0,0]
x = ????
sum = 0
while ?????? :
    sum = sum + coins[????]
    x= ??????
print (sum)


You need to log in or create an account to submit code!

Comments are closed.

Information