有人能用我的代码帮助我吗? (蟒蛇)

时间:2015-10-17 23:18:20

标签: python python-3.x

所以我收到此错误消息:

Traceback (most recent call last):
  File "C:/Users/Ethan/Documents/Coding/test2.py", line 3, in <module>
    buy = input("Marijuana plants cost 200$ ea, opium seeds cost 300$")
  File "<string>", line 1, in <module>
NameError: name 'm' is not defined

我打赌这很明显但是,我是python的新手,需要一些帮助。

代码:

balance = 2500
FinalPrice = 0
buy = input("Marijuana plants cost 200$ ea, opium seeds cost 300$")     
while (buy != "o") and (buy != "m"):
    buy = input("That's not on the market! type 'm' if you want to buy Marijuana and 'o' if you want opium!")
if buy =="o":
    o = input("How many opium seeds? Press c to cancel")
    if o=="0":
        o = input("invalid number, input again")
    elif o =="c":
       input("You cancelled the trade. Type in a command to do something else")
    oprice = (o*300)
    print(oprice)
    FinalPrice-=FinalPrice
    FinalPrice+=oprice
    obuy = input("This is the final price, press b to buy or c to cancel")
    if obuy =="c":
        input("You cancelled the trade. Type in a command to do something else")
    elif obuy =="b":
        if oprice > balance:
            print("Not enough money! Sell more drugs to earn more money.")
        elif oprice < balance:
            print("you bought", o , "Opium seeds for", oprice , "$")
    input("What do you want to do next?")    
elif buy =="m":
    m = input("How many Marijuana plants? Press c to cancel")
    if m=="0":
        m = input("invalid number, input again")
    elif m =="c":
        input("You cancelled the trade. Type in a command to do something else")
    mprice = (m*200)
    print(mprice)
    FinalPrice-=FinalPrice
    FinalPrice+=mprice
    mbuy = input("This is the final price, press b to buy or c to cancel")
    if mbuy =="c":
        input("You cancelled the trade. Type in a command to do something else")
    elif mbuy =="b":
        if mprice > balance:
            print("Not enough money! Sell more drugs to earn more money.")
        elif mprice < balance:
            print("you bought", m , "Marijuana plants for", mprice , "$")
input("What do you want to do next?")

任何帮助将不胜感激。 我让m工作,但后来我实现了o它没有用。

1 个答案:

答案 0 :(得分:0)

此代码应该适用于python 3。

如果您使用的是python 2,那么无论您希望输入是整数类型,请使用

int(raw_input())

接受输入。 只要你想要它是一个字符串,只需使用

的raw_input()