提问人:smgrayhunter 提问时间:11/15/2023 最后编辑:AKXsmgrayhunter 更新时间:11/15/2023 访问量:28
为什么我们在以下代码中收到此错误“File ”<exec>“, line 8 SyntaxError: 'await' outside async function”?
Why are we getting this error " File "<exec>", line 8 SyntaxError: 'await' outside async function" in the following code?
问:
game1 = "rps"
play_game1 = input(f"Would you like to play {game1}? (yes/no): ").lower()
if play_game1 == 'yes':
import random
def get_user_choice():
user_choice = input("Enter your choice (rock, paper, or scissors): ").lower()
while user_choice not in ["rock", "paper", "scissors"]:
print("Invalid choice. Please enter rock, paper, or scissors.")
user_choice = input("Enter your choice (rock, paper, or scissors): ").lower()
return user_choice
def get_bot_choice():
return random.choice(["rock", "paper", "scissors"])
def determine_winner(user_choice, bot_choice):
if user_choice == bot_choice:
return "It's a tie!"
elif (
(user_choice == "rock" and bot_choice == "scissors") or
(user_choice == "paper" and bot_choice == "rock") or
(user_choice == "scissors" and bot_choice == "paper")
):
return "You win!"
else:
return "Bot wins!"
def play_game():
print("Welcome to Rock, Paper, Scissors!")
while True:
user_choice = get_user_choice()
bot_choice = get_bot_choice()
print(f"You chose: {user_choice}")
print(f"Bot chose: {bot_choice}")
result = determine_winner(user_choice, bot_choice)
print(result)
play_again = input("Do you want to play again? (yes/no): ").lower()
if play_again != "yes":
print("Thanks for playing. Goodbye!")
break
if __name__ == "__main__":
play_game()
在“https://programiz.pro/ide/python/”上运行它。
答: 暂无答案
评论