python怎么赋值int_int对象不支持项赋值
我是二年級(jí)的。我在大學(xué)的時(shí)候遇到了一個(gè)問(wèn)題。我要做一個(gè)劊子手游戲,100%喜歡他們的產(chǎn)量和規(guī)格。我會(huì)用數(shù)字格式化列表,但我不知道怎么做,新來(lái)的。我的問(wèn)題出在街區(qū):for i in range(0, stringSize, 1):
answerStr[i] = '_'
它給了我錯(cuò)誤int object does not support item assignment
在其他語(yǔ)言中,我只需要?jiǎng)?chuàng)建一個(gè)大小的字符串(userChosenWord),但是Python的字符串庫(kù)和它的動(dòng)態(tài)類(lèi)型有問(wèn)題。在賦值中,我必須將當(dāng)前字符串輸出為_(kāi)____,如果用戶(hù)想猜e中的單詞horse,我必須告訴用戶(hù)Letters matched so far: ____e。我希望這有道理。
另外,如果你們中有人對(duì)我的代碼有建議/意見(jiàn),請(qǐng)告訴我。我總是想學(xué)習(xí)。wordList = ['cow', 'horse', 'deer', 'elephant', 'lion', 'tiger', 'baboon', 'donkey', 'fox', 'giraffe'] #will work for words <=100 chars
inputList = "abcdefghijklmnopqrstuvwxyz"
illegalInputList = "!@#$%^&*()_+-=`~;:'\".?/|\\}]{["
def game():
attemptsMade = 0
print("Welcome to Hangman. Guess the mystery word with less than 6 mistakes.")
userInputInteger = int(input("Please enter an integer number (0<=number<10) to choose the word in the list:"))
if (0 > userInputInteger or userInputInteger > 9):
print("Index is out of range.")
game()
for i in range(0, len(wordList)):
if (userInputInteger == i):
#userChosenWord is string from wordList[i]
userChosenWord = wordList[i]
print("The length of the word is:", len(userChosenWord))
break
stringSize = len(userChosenWord)
answerStr = len(userChosenWord)
#make a temp string of _'s
for i in range(0, stringSize, 1):
answerStr[i] = '_'
keyStr = userChosenWord
def play():
guessChar = input("Please enter the letter you guess:")
if guessChar not in inputList:
print("You must enter a single, alphabetic character.")
play()
if guessChar in illegalInputList:
print("Input must be an integer.")
play()
if (guessChar == ('' or ' ')):
print("Empty input.")
play()
attemptsMade += 1
if guessChar in userChosenWord:
for i in range(0, stringSize, 1):
if (keyStr[i] == guessChar):
answerStr[i] = guessChar
print("Letters matched so far: %s", answerStr)
else:
print("The letter is not in the word.")
play()
if (answerStr == userChosenWord):
print("You have guessed the word. You win. \n Goodbye.")
sys.exit()
if (attemptsMade <= 6):
play()
if (attemptsMade > 6):
print("Too many incorrect guesses. You lose. \n The word was: %s", userChosenWord)
replayBool = bool(input("Replay? Y/N"))
if (replayBool == 'y' or 'Y'):
play()
elif (replayBool == 'n' or 'N'):
print("Goodbye.")
game()
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的python怎么赋值int_int对象不支持项赋值的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: as常用固定搭配_英语考试干货!205个
- 下一篇: python填写excel内容_pyth