2016-06-13 58 views
-3

我是python的初學者,它總是說我在2,4和10行有一個不好的輸入,當我在第二行前面寫上<時,它會批准它,當我把>的4號線就批准它,我試了10日線,但讓我有種改變它一點也沒有工作python文字遊戲上的錯誤

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: ")) 

回答

1

Python中的「=」符號用於給變量簽名一個值。 例如:

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

用於比較使用「==」。例如:

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