I'm trying to create a simple fruit store with apples and grapes for sale. I've set the amounts of each fruit to be randomised.
If you ask for more grapes then the store has, I want the code to loop back and ask for another input. I'm stuck on that. Here is my code:
import random
amount_of_apples = random.randint(1, 100)
price_of_apples = random.randint(1, 10)
amount_of_grapes = random.randint(1, 50)
price_of_grapes = random.randint(5, 15)
stock = ["apples","grapes"]
basket = []
greeting = """Hello and welcome to Pennants."""
availability = "We have the following fruits available to purchase " + stock[0] + " and " + stock[1]
print(greeting)
print(availability)
print("""We have %s Apples available to purchase. Each Apple cost £%s.""" % (amount_of_apples, price_of_apples))
print("""We have %s bunches of grapes available to purchase. Each bunch of grapes cost £%s.""" % (amount_of_grapes, price_of_grapes))
order = input("What would you like to purchase?")
if order == " Grapes":
basket.append("Grapes")
def order_check():
G2 = input("How many bunches of grapes would you like to buy?")
print("Your basket:" + G2 + basket[0])
Correct = "Yes"
Incorrect = "No"
M = int(G2) * price_of_grapes
if int(G2) > amount_of_grapes:
print("""Unfortunately we don't have enough grapes to fufil your request.
We have %s grapes available to buy.""" % (amount_of_grapes))
order_check()