-3
我有下面的代碼有問題:在引用錯誤出現之前調用的Python函數?
#1/usr/bin/env python3
import random
financialPoints = 0
debatePointsT = 0
marginalCheck = random.randint(0,1)
debatePointsTO = 0
Choice = random.randint(0,2)
popularity = 0
name = input("What is your first name")
nameSur = input("What is your surname")
print("This is the political campaign simulator")
chosenParty = input("Choose a party. A - LibDem, B - Labour, C- Tory")
if chosenParty == "C":
print("You have been elected as a councillor by your fellow peers.")
marginality = input("They want you to stand as a MP in a seat. Do you want to stand in a safe or marginal seat")
if marginality == "marginal":
if marginalCheck == 0:
print("You have failed to be elected to parliament")
else:
print("You are duly elected the MP for your constituency!")
campaignT()
else:
campaignT()
def debateT():
#My Code
if marginality == "safe":
campaignT()
def campaign():
#My Code
if elected == True:
debateT()
它告訴我,我引用它之前被調用的函數,但是我需要它在那裏等我來運行代碼的另一部分,如您可以看到上面。在python中有沒有辦法讓函數並行執行,或者類似的東西?
你是什麼意思,「我需要它在那裏」?是否向你提供了大部分代碼,並且只允許/預期填寫函數體? –
@Anish,你正在底層定義一個函數'campaign',但是在if-else塊中調用'campaignT'函數。除此之外,將函數放在文件的頭部。 –
我需要它,所以我可以使用這些變量 – Anish