日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

python怎么赋值int_int对象不支持项赋值

發(fā)布時(shí)間:2023/12/19 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python怎么赋值int_int对象不支持项赋值 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我是二年級(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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。