Итак, в настоящее время я создаю игру для небольшого биржевого брокера, используя python для моего задания, и я столкнулся с проблемой. Мой следующий урок не раньше вторника на следующей неделе, и я не могу найти какие-либо хорошие решения для моей проблемы. По сути, этот код предназначен для первоначального уменьшения времени на 1 каждый раз, когда игрок решает подождать день, однако время остается равным 20, независимо от того, сколько раз игрок ждет. Я также не уверен, как сделать так, чтобы мой код зацикливал раздел ввода пользователя: «Вы хотели покупать акции, продавать акции или ждать день?» Пока пользователь не скажет, что хотел бы подождать. Есть ли исправление для этой проблемы, и если да, то что это? Вот код, о котором я говорю:
stocks = 0
time = 21
money = 100
print("You have $" + str(money) + " in your bank.")
while time > 0:
stock = random.randint(1,20)
time = time - 1
while True:
print("You have " + str(time) + " days remaining until the market closes")
print("Stocks are currently worth: $" + str(stock))
choice = input("Did you want to buy stocks, sell stocks or wait a day? ")
if choice.casefold() == "buy":
while True:
numberBuy = int(input("Enter the number of stocks that you would like to buy: "))
if numberBuy * stock > money:
print("You don't have the money for that")
else:
break
money = money - (numberBuy * stock)
stocks = stocks + numberBuy
print("You bought " + str(numberBuy) + " stocks and you spent $" + str(numberBuy * stock) + " buying them. You now have $" + str(money) + " and you have " + str(stocks) + " stocks")
elif choice.casefold() == "sell":
while True:
numberSell = int(input("Enter the number of stocks that you would like to sell: "))
if numberSell > stocks:
print("You don't have enough stocks for that. You have " + str(stocks) + " stocks and you want to sell " + str(numberSell))
else:
break
stocks = stocks - numberSell
money = money + (numberSell * stock)
print("You sold " + str(numberSell) + " stocks and you made $" + str(numberSell * stock) + " selling them. You now have $" + str(money) + " and you have " + str(stocks) + " stocks")
elif choice.casefold() == "wait" or "wait a day" or "wait day":
print("You wait for the next day to come. At the end of the day, you have $" + str(money) + " in your bank account and you have " + str(stocks) + " stocks to")
print("your name")
print(" ")
print("===========================================================================================================")
print(" ")```