How would I code this in the problem below in python? Halloween Candy Create a v
ID: 3606382 • Letter: H
Question
How would I code this in the problem below in python?
Halloween Candy
Create a virtual trick-or-treat candy bag. It should be a problem starting with a list of candy (strings) as elements. Then, you should allow the user to either "look inside" the bag or to "eat" a piece of candy. Eating a piece of candy shows the candy eaten on the screen but removes it from the list as well.
1. Your answer should use these concepts: lists, popping, loops, strings and anything else you need to complete the problem.
Explanation / Answer
candy = ['Almond_Joy','Aplets','Cotlets','Ayds','Big_Hunk','Candy_Raisins','Mounds']
menu = "Please Choose Option from below: 1. Look inside the bag 2. Eat a candy "
print(menu)
prompt = "Please enter your choice: "
choice = int(input(prompt))
if (choice == 1):
print("Candies avaiable are: ")
for i in range(len(candy)):
print(candy[i])
else:
if(choice == 2):
candyChoice = input("Enter the candy you want to eat: ")
if candyChoice in candy:
candy.pop(candy.index(candyChoice))
else:
print("Candy not avaiable.")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.