所以我有一个名为LoopingSpace的函数。它不需要参数
def loopingSpace():
for i in range (3):
print ""
i +=1
每当被召唤时。它将打印三个空白行。 例如;如果我输入
def loopingSpace():
for i in range (3):
print ""
i +=1
print"Hi"
loopingSpace()
print"Hi"
很好地输出
Hi
Hi # As you can see three blanks.
但是,当你将这个函数放在像。
这样的庞大语法中时from random import randint
#Variabel
#--------------------------------------------------------------------
playername=[]
#Player disini mencatat skor. Jumlah Uang/Nilai Saham/Total harta/Health
playerOne=[0,0,0,0]
playerTwo=[0,0,0,0]
playerThree=[0,0,0,0]
#Stok disini mencatat banyak saham yang dimiliki peserta. A/B/C/D/E/F/G/H
stockOne=[0,0,0,0,0,0,0,0]
stockTwo=[0,0,0,0,0,0,0,0]
stockThree=[0,0,0,0,0,0,0,0]
#Tool disini mencatat apabila peserta memiliki barang. Diamond/Buy/Sell/Diamond/Poison
toolOne=[0,0,0,0,0]
toolTwo=[0,0,0,0,0]
toolThree=[0,0,0,0,0]
#Price disini mencatat harga saham. A/B/C/D/E/F/G/H
price=[0,0,0,0,0,0,0,0]
#clockTracker. Day dan turn counter
clockTracker=[0,0]
hari=["Senin","Selasa","Rabu","Kamis","Jumat","Sabtu","Minggu"]
listing=[playerOne,playerTwo,playerThree]
toolListing=[toolOne,toolTwo,toolThree]
#Nama saham
stockName=["Alama Inc.","Bwah! Bwah! Bwah! LCD","CUIT! CUIT CV","Dong Inc.","Eeeeeeeeeeeeah!","Foo il company.","Gogogogo Ind.","Halllo."
#--------------------------------------------------------------------
# THIS IS THE CODE. THIS IS THE CODE. THIS IS THE CODE
def loopingSpace():
for i in range (3):
print ""
i +=1
#
def startingTheGame():
loopingSpace()
print "Selamat datang di Stock Game."
print "Anda mau [M]ain atau Baca [A]turan?"
answer= raw_input(">")
answerRecognizerOne(answer)
#
def answerRecognizerOne(inbox):
inbox.lower()
if inbox=="a":
ruleExplainer()
elif inbox=="m":
gameStarter()
else:
loopingSpace()
print "Syntax tidak dimengerti. Mohon ulangi."
loopingSpace()
startingTheGame()
#
def answerRecognizerTwo(inbox):
inbox.lower()
if inbox=="y":
print "Kita akan mengambil kartu kesempatan lagi"
cekKartuKesempatan()
elif inbox=="n":
print "Game akan dilanjutkan"
#
def ruleExplainer():
loopingSpace()
print "Aturan:"
print "Dalam awal giliran kamu, kamu akan mengambil kartu kesempatan."
print "Kartu kesempatan kamu akan memberikan kamu hak untuk mengubah harga saham."
print "Lalu kamu bisa jual atau beli saham."
print "Kamu juga dapat bekerja pada Weekend, sehingga kamu dapat uang tambahan."
print "Setelah 33 hari. Peserta dengan uang tertinggi akan menang."
loopingSpace()
startingTheGame()
#
def gameSetUp():
playerOne=[250,0,0]
playerOne[2]=playerOne[0]+playerOne[1]
playerTwo=[250,0,0]
playerTwo[2]=playerTwo[0]+playerTwo[1]
playerThree=[250,0,0]
playerThree[2]=playerThree[0]+playerThree[1]
price=[30,30,30,30,30,30,30,30]
print playerOne
print playerTwo
print playerThree
print price
loopingSpace()
print "Saya akan memberi kamu semua $250 untuk berinvestasi."
print "Kamu juga akan memasuki dunia Wallsheet."
print "Sebuah bursa saham di dunia Kryxban."
print "Semoga beruntung."
loopingSpace()
answer= raw_input ("Tekan enter untuk melanjutkan")
clockTracker=[1,0]
print "Good Luck"
loopingSpace()
kartuKesempatan()
#
def refreshScore():
playerOne[1]=0
for i in range(8):
playerOne[1]+=(stockOne[i]*price[i])
playerTwo [1]=0
for i in range(8):
playerTwo[1]+=(stockTwo[i]*price[i])
playerThree [1]=0
for i in range(8):
playerThree[1]+=(stockThree[i]*price[i])
playerOne[2] = playerOne[0] + playerOne[1]
playerTwo[2] = playerTwo[0] + playerTwo[1]
playerThree[2] = playerThree[0] + playerThree[1]
# Fungsi printScore -> Mengprint skor
def printScore():
print playername[0]+": Uang: $"+str(playerOne[0])+" Saham: $"+str(playerOne[1])+" Total: $"+str(playerOne[2])
print playername[1]+": Uang: $"+str(playerTwo[0])+" Saham: $"+str(playerTwo[1])+" Total: $"+str(playerTwo[2])
print playername[2]+": Uang: $"+str(playerThree[0])+" Saham: $"+str(playerThree[1])+" Total: $"+str(playerThree[2])
# Fungsi kartuKesempatan -> Menjalankan fase Kartu Kesempatan
def kartuKesempatan ():
refreshScore()
print "Sekarang adalah giliran " + playername[clockTracker[1]]
print ""
printScore()
loopingSpace()
print "Kamu mengambil kartu kesempatan"
answer = raw_input ("Kamu siap? Tekan enter jika kamu siap?")
cekKartuKesempatan()
#
def gameStarter():
print loopingSpace()
for i in range(3):
answer= raw_input("Masukan nama pemain ke " + str(i+1)+ ">")
playername.append(answer)
gameSetUp()
#
def cekKartuKesempatan():
foo = randint(1,2)
if foo==1:
print "**KAMU MENDAPAT $25**"
print "Dompet kamu tiba-tiba memberat."
print "Kamu mengecek dompetmu."
print "Ada $25 muncul!"
(listing[clockTracker[1]][0])+=25
updateScore()
checkForToool()
elif foo==2:
print "**SAHAM NAIK 10%**"
woo=0
for i in range(8):
woo= floor.(price[i]/10)
if woo != 0:
price[i] += woo
print "Saham "+stockName[i]+" naik $"+woo
checkForTool()
def checkForTool()
if (toolListing[clockTracker[1]][0])!=0:
print "Anda mempunyai 'Kesempatan Extra'. Mau dipakai? ( Anda punya "+str.(toolListing[clockTracker[1]][0])+" ) [y]es /[n]o"
answer= raw_input(">")
answerRecognizerTwo(answer)
它抛出了这个错误。
File "main.py", line 31
def loopingSpace():
^
SyntaxError: invalid syntax
注意:我使用在线执行器 注意:在线执行者分别使用2.7.4和2.7.5
我哪里做错了?
注意:当我完全从代码中删除loopingSpace():函数时,它会抱怨下一行中的函数,在本例中为startingTheGame(),依此类推
PS:这个pyt形成一个游戏。我将调用一个函数(startingTheGame()),此函数将调用其他函数,依此类推。我很确定你明白了这一点。
此致
DEO
答案 0 :(得分:1)
语法错误实际上在它之前的行:
stockName=["Alama Inc.","Bwah! Bwah! Bwah! LCD","CUIT! CUIT CV",
"Dong Inc.","Eeeeeeeeeeeeah!","Foo il company.",
"Gogogogo Ind.","Halllo."
您必须添加右括号]
:
stockName=["Alama Inc.","Bwah! Bwah! Bwah! LCD","CUIT! CUIT CV",
"Dong Inc.","Eeeeeeeeeeeeah!","Foo il company.",
"Gogogogo Ind.","Halllo."]
答案 1 :(得分:0)
目前,您的列表定义为:
stockName = [“Alama Inc。”,“Bwah!Bwah!Bwah!LCD”,“CUIT!CUIT CV”,“Dong Inc。”,“Eeeeeeeeeeeeah!”,“Foo il company。”,“Gogogogo Ind” 。 “” Halllo。“
请注意列表末尾没有]
。因此,您在技术上尚未定义列表,因此python尝试继续创建列表。然后它用文本读取下一行,即def loopingSpace():
。由于语法[..., "Halllo." def loopingSpace()
不是正确的语法,因此在定义行引发SyntaxError
。