0% found this document useful (0 votes)
405 views1 page

FruitBasket Python

This Python code defines a FruitBasket class with a main method that allows a user to catch and eat virtual fruits. The user selects how many fruits to catch and picks from options of apple, orange, mango, and guava by entering letters. The caught fruits are stored in a stack. The user can then eat fruits from the basket by entering E, which pops fruits off the stack, until the basket is empty.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
405 views1 page

FruitBasket Python

This Python code defines a FruitBasket class with a main method that allows a user to catch and eat virtual fruits. The user selects how many fruits to catch and picks from options of apple, orange, mango, and guava by entering letters. The caught fruits are stored in a stack. The user can then eat fruits from the basket by entering E, which pops fruits off the stack, until the basket is empty.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class FruitBasket(object):

def main(args):
print("Catch and eat any of these fruits : ('apple', 'orange','mango',
'guava')")
print("How many of these fruits would you like to catch? ", end = '')
fruits = [Link]()
i = None
select = None
print("Choose a fruit to catch. Press A, O, M or G.")
i = 1
while i <= fruits:
print("Fruit " + i + " of " + fruits + " : ", end = '')
select = [Link]().charAt(0)
if select == 'a':
[Link]("'apple' ")
elif select == 'o':
[Link]("'orange' ")
elif select == 'm':
[Link]("'mango' ")
elif select == 'g':
[Link]("'guava' ")
else:
print("You input wrong letter please pick only A, O, M or G.")
i += 1
print("Your basket now has: " + st)
while True:
print("Press E to eat a fruit: ", end = '')
eat = [Link]().charAt(0)
if eat == 'e' or eat == 'E':
[Link]()
print("Fruit(s) in the basket = " + st)
if [Link]():
print("No more fruits.")
break
else:
print("You input wrong letter please pick only E.")

You might also like