python怎么赋值int_int对象不支持项赋值
我是二年級的。我在大學的時候遇到了一個問題。我要做一個劊子手游戲,100%喜歡他們的產量和規格。我會用數字格式化列表,但我不知道怎么做,新來的。我的問題出在街區:for i in range(0, stringSize, 1):
answerStr[i] = '_'
它給了我錯誤int object does not support item assignment
在其他語言中,我只需要創建一個大小的字符串(userChosenWord),但是Python的字符串庫和它的動態類型有問題。在賦值中,我必須將當前字符串輸出為_____,如果用戶想猜e中的單詞horse,我必須告訴用戶Letters matched so far: ____e。我希望這有道理。
另外,如果你們中有人對我的代碼有建議/意見,請告訴我。我總是想學習。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()
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python怎么赋值int_int对象不支持项赋值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: as常用固定搭配_英语考试干货!205个
- 下一篇: thinkCMF----导航高亮显示