0% found this document useful (0 votes)
340 views

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)
340 views

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
You are on page 1/ 1

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 = sc.nextInt()
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 = input.next().charAt(0)
if select == 'a':
st.push("'apple' ")
elif select == 'o':
st.push("'orange' ")
elif select == 'm':
st.push("'mango' ")
elif select == 'g':
st.push("'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 = sc.next().charAt(0)
if eat == 'e' or eat == 'E':
st.pop()
print("Fruit(s) in the basket = " + st)
if st.empty():
print("No more fruits.")
break
else:
print("You input wrong letter please pick only E.")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy