我一直在四處查看,但是一直無法解決此錯誤。 也作爲一個方面的問題這個錯誤之前,該計劃將始終打印星期的平均水平沒有發生什麼問題,可能的發生的其他2個變量沒有在分配之前引用的局部變量'fight_run'
這是所有在Python
from random import randint
import time
money = 2000
week = 0
def stockmarket():
global money
global week
stock = int(randint(1,50))
fight_random = int(randint(1,4))
fight = int(randint(1,100))
gain_lose = int(randint(1,2))
win_lose_var = int(randint(1,30))
luck = int(0)
if money > 10000 :
print ("""congratulations you beat the game by earning 10,000
now that you have so much money you can go back to your life as a hip hop artist """)
time.sleep(4)
print("it took you ",week,"weeks's to compleate the game")
print("can you do it faster next time")
else:
print(" you have gained lots of money",money,"")
print("you must now invest it all the stock market")
human_stock = int(input("please pick a number between 1-100 not that it matters as the markets are rigged: "))
#need to make the user number matter
change1 = int(stock-40+luck)
change2 = float (change1/100)
change3 = float (1-change2)
money = money * change3
week = week+1
print ("you have" , money,"")
week = week +1
#THIS IS WHERE THE PROBLEM STARTS!
if fight == 3:
print("bad luck")
fight_run = str(input("""late at night you get approched by a bunch of bad, bad people. they attempt to mugg you but you see there is a chance to run away but you could fight
them and gain lots of money! do you fight or run"""))
if fight_run == "run":
print("you fled the scene but left some money behind which has been stolen.")
money *=.8
print(" ",money," ")
stockmarket()
if fight_run == "fight" :
print ("you chose to fight the oncoming enemys!")
if fight < 0 or fight > 11:
print("you where over powered by your enemys and died")
time.sleep(5)
quit()
elif fight <10 and fight >80 :
win_lose = int(input("the fight is close and you are both weak. /n please pick and number between 1 and 30 for a chance to gain money!"))
elif gain_lose == 1:
print("you deafeated your attacckers and take there money (its not a crime if no one saw)")
money_fight_win = (win_lose/100)+ 1
money = money * money_fight_win
print ("",money,"")
elif gain_lose == 2 :
print ("your attacker won and they took your money luckly you hide some just before the fight ")
money_fight_lose = (win_lose/100)+ 1 - (winlose/50)
money = money * money_fight_lose
else :
print("you mortaliy wounded the atackers (cause ur dench m8) and took their money")
money = money *1.5
#loop
stockmarket()
if fight == 4:
print ("you found a lucky penny and added it to your penny collection")
luck = +1
elif fight == 1 or 2:
print("your week was average nothing much happened")
#loop
stockmarket()
#gets program to start
stockmarket()
我剛剛刪除了一個類似的答案,因爲這個更清晰。另外,如果我輸入「尿褲子」而不是「跑步」或「打架」呢? – RobertB
儘管您已經對輸入驗證做了一個很好的說明。他目前不執行互斥輸入檢查或驗證輸入是可消化的。 – saarrrr
好的,我刪除了我的刪除答案,即使有很多重疊。 :) – RobertB