日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/19 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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对象不支持项赋值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。