Write a python program that uses loops to take in 10 colors/flavors of pez candy
ID: 3698584 • Letter: W
Question
Write a python program that uses loops to take in 10 colors/flavors of pez candy from a user and add them to a virtual pez dispenser (array). The script should print out the contents of the dispenser before taking in the input to show that the pez dispenser is empty. After the dispenser has been loaded using a loop, the contents of the dispenser should be printed out to show that it is full. The program should then dispense the candy 1 piece at a time and conclude by printing out the contents of the dispenser, showing that it is now empty Write a python program that uses loops to take in 10 colors/flavors of pez candy from a user and add them to a virtual pez dispenser (array). The script should print out the contents of the dispenser before taking in the input to show that the pez dispenser is empty. After the dispenser has been loaded using a loop, the contents of the dispenser should be printed out to show that it is full. The program should then dispense the candy 1 piece at a time and conclude by printing out the contents of the dispenser, showing that it is now emptyExplanation / Answer
paste the following code in a file like pez.py and excute the code using this command: python pez.py
dispenser = [ ]
length = 0
print "Dispenser is Empty now ...! ", dispenser
while (length<10):
dispenser.append(raw_input("Enter the color "+str(length)))
length +=1
print "Dispenser is Full now ...!", dispenser
length = 0
while (length<10):
print "Piece ", length, ": ", dispenser[length]
length +=1
del dispenser[:10]
print dispenser
print "Now the Dispenser is Empty"
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.