python单词gam中的错误

2024-06-06 05:12:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python的初学者,它总是说我在第2行、第4行和第10行的输入不好,当我输入一个<;在第二行前面,它批准了它,当我将>;对于第四行,它批准它,我尝试了第十行,但它没有工作

start = int(input("type 1 to begin or 2 to buy items: "))
if start = 1 :
    print("welcome to this game")
if start = 2 :
    ranged = 0
    melee = 1
    fighting = 0
    money = 100
    shop = int(input("1 for sword or two for arrows: "))
        if shop = 1 :
            money = money-100
            fighting = fighting+1
            melee = melee+1
            start = int(input("type 1 to begin or 2 to buy items: "))
        if shop = 2 :
            money = money-100
            fighting = fighting+0.5
            ranged = ranged+1
            start = int(input("type 1 to begin or 2 to buy items: "))
        else:
        print("invalid selection")`

嗯,所以我稍微修改了一下,但是第12行仍然有错误,它说它不能识别x,但是我已经在前面定义过了

start = int(input('type 1 to begin or 2 to buy items: '))
if start == 1 :
    print("welcome to this game")
    print("you will face off with a evil monster named york for the first adventure")
    print("I am york and I will eat you")
if start == 2 :
    x = float(input('type 1 or 2 to buy items: '))
    ranged = 0
    melee = 1
    fighting = 0
    money = 100
if x == 1:
    money = money-100
    print(money)
    fighting = fighting+1
    melee = melee+1
    start = int(input('type 1 to begin or 2 to buy items: '))
    if start == 1 :
        print("welcome to this game")
    else:
        print("visit the shop another time")
if x == 2 :
    money = money-100
    fighting = fighting+0.5
    ranged = ranged+1
    start = int(input("type 1 to begin or 2 to buy items: "))

Tags: ortoinputiftypeitemsbuystart
1条回答
网友
1楼 · 发布于 2024-06-06 05:12:54

Python中的“=”符号用于为变量赋值。 示例:

>>> x = 3
>>> x+1
4

比较时使用“==”。 示例:

>>> if x == 3:
...     print "That is true"
...
That is true
>>> if x == 2:
...     print "that is true"
...
>>>

相关问题 更多 >