[英]Can someone help me with my code? (python)
所以我收到此錯誤消息:
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 並且它沒有用。
這段代碼應該適用於 python 3。
如果您使用的是 python 2,那么無論您希望輸入為整數類型,請使用
int(raw_input())
接受輸入。 每當您希望它是一個字符串時,只需使用
原始輸入()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.