-2
我想編程主謀(遊戲),在我for
循環在這一行::刪除函數調用錯誤?
del cpureturn(rndm_cpureturn)
我不斷收到同樣的錯誤:
SyntaxError: can't delete function call
這是爲什麼發生和我如何解決它?
#Mastermind
import random as r
import sys
#Color Database
colorpegs = ['blue', 'black', 'red', 'white', 'yellow', 'green']
correctingpegs = ['White', 'Black']
#CPU Code Generator
code1 = r.choice(colorpegs)
code2 = r.choice(colorpegs)
code3 = r.choice(colorpegs)
code4 = r.choice(colorpegs)
cpucode = [code1, code2, code3, code4]
#Player Guessing
print('')
print('')
print('Colors: Blue, Black, Red, White, Yellow, Green')
guessround = 1 #Says what try, For amount of tries
print(cpucode)
while guessround <= 10:
print('')
print('Guess Round %s/10' %(guessround))
guess1 = input('Guess code color 1: ') #Inputting Colors
guess2 = input('Guess code color 2: ')
guess3 = input('Guess code color 3: ')
guess4 = input('Guess code color 4: ')
print('')
print('Your guesses were: %s %s %s %s ' % (guess1, guess2, guess3, guess4))
cpureturn = [] #Step1 to cpureturn randomization
if guess1 == cpucode[0]: #Guess 1
cpureturn.append('Black')
elif guess1 == cpucode[1] or guess1 == cpucode[2] or guess1 == cpucode[3] and guess1 != code1:
cpureturn.append('White')
else:
cpureturn.append('Nothing')
if guess2 == cpucode[1]:#Guess2
cpureturn.append('Black')
elif guess2 == cpucode[0] or guess2 == cpucode[2] or guess2 == cpucode[3] and guess2 != code2:
cpureturn.append('White')
else:
cpureturn.append('Nothing')
if guess3 == cpucode[2]:#Guess3
cpureturn.append('Black')
elif guess3 == cpucode[1] or guess3 == cpucode[0] or guess3 == cpucode[3] and guess3 != code3:
cpureturn.append('White')
else:
cpureturn.append('Nothing')
if guess4 == cpucode[3]:#guess4
cpureturn.append('Black')
elif guess4 == cpucode[1] or guess4 == cpucode[2] or guess4 == code4[0]:
cpureturn.append('White')
else:
cpureturn.append('Nothing')
for i in range(1, 5):
rndm_cpureturn = (r.choice(cpureturn))
print(rndm_cpureturn)
del cpureturn(rndm_cpureturn)
if guess1 == code1 and guess2 == code2 and guess3 == code3 and guess4 == code4 and guessround != 10 :
print('')
print('')
print('')
print('WE HAVE A WINNER')
sys.exit()
if guessround == 10:
print('You Lose, better luck next time')
print('The code was' + cpucode)
sys.exit()
guessround = guessround + 1
但是會'德爾cpureturn(rndm_cpureturn)'甚至是什麼意思?請解釋發生了什麼,以及您希望程序的幾個部分要做什麼,而不是傾倒程序? –
您是否嘗試刪除變量cpureturn?如果不是,你想要那行代碼做什麼? – Ben