Okey, so im learning python and im trying to create this basic pick-sell game...
import random
global gold
gold = 0
class Fruit:
def __str__(self):
return self.name
def __repr__(self):
return self.name
class Apple(Fruit):
def __init__(self):
self.name = "Apple"
self.desc = "An Red Apple!"
self.value = "2 Gold"
class Grapes(Fruit):
def __init__(self):
self.name = "Grapes"
self.desc = "Big Green Grapes!"
self.value = "4 Gold"
class Banana(Fruit):
def __init__(self):
self.name = "Banana"
self.desc = "Long, Fat Yellow Bananas"
self.value = "5 Gold"
class Orange(Fruit):
def __init__(self):
self.name = "Orange"
self.desc = "Big Orange Orange"
self.value = "7 Gold"
inventory = []
print ("Fruits!")
print ("To see your inventroy press: i")
print ("To sell fruits press: s")
print ("To pick fruits press: p")
def action():
return input("Action: ")
def i ():
print ("Your Inventory: ")
print ("*" + str(inventory))
def p ():
pick = [Apple(), Orange(), Grapes(), Banana()]
inventory.append (random.choice(pick))
def s ():
print ("...")
while True:
actioninput = action()
if actioninput in ["i", "İ"]:
i ()
elif actioninput in ["s", "S"]:
s ()
elif actioninput in ["p", "P"]:
p ()
else:
print ("Invalid Action!")
So my questions is:
in def p():, i would like to print the item that has been added to the list. i tryed some things but they didn't work...
I have no idea how to do a "sell" function, how can i delete an item from the list and add it's value to global gold?
i edited the def s(): as like this and i get an error:
def s():
global gold
sell = input ("What item would you like to sell?")
if sell == "Apple":
inventory.remove (Apple)
gold = gold + 2
elif sell == "Orange":
inventory.remove (Orange)
gold = gold + 7
elif sell == "Banana":
inventory.remove (Banana)
gold = gold + 4
elif sell == "Grapes":
inventory.remove (Grapes)
gold = gold + 5
ValueError: list.remove(x): x not in list