python类不接受任何参数_python – TypeError:类型为’NoneType’的参数不可迭代

我正在使用

Python制作一个Hangman游戏.在游戏中,一个python文件具有从数组中选择随机字符串并将其存储在变量中的函数.然后将该变量传递给另一个文件中的函数.该函数将用户猜测存储为变量中的字符串,然后检查该猜测是否在该单词中.但是,每当我输入一个字母并按回车键时,我会在此问题的标题中收到错误.你知道,我正在使用Python 2.7.这是接受一个单词的函数的代码:

import random

easyWords = ["car", "dog", "apple", "door", "drum"]

mediumWords = ["airplane", "monkey", "bananana", "window", "guitar"]

hardWords = ["motorcycle", "chuckwalla", "strawberry", "insulation", "didgeridoo"]

wordCount = []

#is called if the player chooses an easy game.

#The words in the array it chooses are the shortest.

#the following three functions are the ones that

#choose the word randomly from their respective arrays.

def pickEasy():

word = random.choice(easyWords)

word = str(word)

for i in range(1, len(word) + 1):

wordCount.append("_")

#is called when the player chooses a medium game.

def pickMedium():

word = random.choice(mediumWords)

for i in range(1, len(word) + 1):

wordCount.append("_")

#is called when the player chooses a hard game.

def pickHard():

word = random.choice(hardWords)

for i in range(1, len(word) + 1):

wordCount.append("_")

现在这里是用户猜测的代码,并确定它是否在为游戏选择的单词中(不要注意wordCount变量.另外,“words”是带有上述代码的文件的名称.) ):

from words import *

from art import *

def gamePlay(difficulty):

if difficulty == 1:

word = pickEasy()

print start

print wordCount

getInput(word)

elif difficulty == 2:

word = pickMedium()

print start

print wordCount

elif difficulty == 3:

word = pickHard()

print start

print wordCount

def getInput(wordInput):

wrong = 0

guess = raw_input("Type a letter to see if it is in the word: \n").lower()

if guess in wordInput:

print "letter is in word"

else:

print "letter is not in word"

到目前为止,我已经尝试将gamePlay函数中的“guess”变量转换为带有str()的字符串,我尝试使用.lower()将其设置为小写,并且我在单词文件中做了类似的事情.这是我运行时遇到的完整错误:

File "main.py", line 42, in

main()

File "main.py", line 32, in main

diff()

File "main.py", line 17, in diff

gamePlay(difficulty)

File "/Users/Nathan/Desktop/Hangman/gameplay.py", line 9, in gamePlay

getInput(word)

File "/Users/Nathan/Desktop/Hangman/gameplay.py", line 25, in getInput

if guess in wordInput:

你看到的“main.py”是我写的另一个python文件.如果你想看到其他人让我知道.但是,我觉得我展示的是唯一重要的.感谢您的时间!如果我遗漏任何重要细节,请告诉我.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值