首页 > 解决方案 > python - 期望一个缩进块while循环

问题描述

所以这是我的代码,创建一个石头剪刀布游戏。我没有别的要说,但这里的系统说我需要更多细节,因为代码太多所以我随机输入。不过谢谢你。

options=["rock","paper","scissors"]

your_wins=0
my_wins=0

while input!="exit":
    turn = input("Please choose rock,paper or scissors:")
    print("you chose:" + turn)

    import random
    my_choice = random.choice(options)
    print("I chose:" + my_choice)

    if my_choice=="rock" and turn=="rock":
        print("its a tie!")

    if my_choice=="paper" and turn=="rock":
        print("you lose!")

    if my_choice=="scissors" and turn=="rock":
        print("you win!")

    if my_choice=="paper" and turn=="paper":
        print("its a tie!")

    if my_choice=="scissors" and turn=="paper":
        print("you lose!")

    if my_choice=="rock" and turn=="paper":
        print("you win!")

    if my_choice=="paper" and turn=="scissors":
        print("you win!")

    if my_choice=="scissors" and turn=="scissors":
        print("its a tie!")

    if my_choice=="rock" and turn=="scissors":
        print("you lose!")
    if "you lose":
        my_wins+=1
    else:
        your_wins+=1

if input=="exit":
break

为什么我会收到此错误?它在休息。我尝试了不同的方法,但它不起作用..谢谢你的帮助!!

标签: pythonwhile-loopbreak

解决方案


在 while 循环中包含“if input == 'exit'”,然后在其中缩进“break”


推荐阅读