【问题标题】:python - expected an indented block while looppython - 期望一个缩进块while循环
【发布时间】:2018-11-06 06:36:27
【问题描述】:

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

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

为什么会出现这个错误?它在休息。 我尝试了不同的东西,但它就是行不通.. 谢谢你的帮助!!

【问题讨论】:

  • 我看到的唯一错误是break 语句最后没有在if 下缩进,但是整个if 语句也应该旨在使其成为@987654325 的一部分@循环。
  • 无论您遇到什么错误,都应包括发生错误的行;您应该始终发布您收到的准确错误消息。

标签: python while-loop break


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-17
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    相关资源
    最近更新 更多