【发布时间】:2025-11-30 00:15:02
【问题描述】:
我制作了这个刽子手程序,但每当我运行它时它都会给出“nonetype”错误 程序运行—— 每当我输入一个单词时,输出是这样的 挂人游戏 猜一个字 一个 ----- 一个字你猜对了
-----a---------------
Traceback (most recent call last):
File "F:/coding/python/python programming for absolute beginners/chapter 5/Hang Man Game.py", line 129, in <module>
if guess in used:
TypeError: argument of type 'NoneType' is not iterable
代码:
print("\t\t\tHang Man Game")
import random
set=("happy","australia","punjab","criclet","tennis")
choose=random.choice(set)
correct=choose
HANGMAN=('''
_______
|
|
|
|
|
|
|
|
|
|
|
___
''',
'''
______________
| |
|
|
|
|
|
|
|
|
|
___
''',
'''
______________
| |
| O
|
|
|
|
|
|
|
|
___
''',
'''
______________
| |
| O
| |
| |
| |
| |
|
|
|
|
___
''',
'''
______________
| |
| O
| |
| ---|
| |
| |
|
|
|
|
___
''',
'''
______________
| |
| O
| |
| ---|---
| |
| |
|
|
|
|
___
''',
'''
______________
| |
| O
| |
| ---|---
| |
| |
| /
| /
| /
|
___
''',
'''
______________
| |
| O
| |
| ---|---
| |
| |
| / \
| / \
| / \
|
___
'''
)
MAX_WRONG=(len(HANGMAN)-1)
wrong=0
new=""
used=[]
so_far="-"*len(correct)
guess=raw_input("Guess a word\n")
while(so_far!=correct and wrong<MAX_WRONG):
print(so_far)
if guess in used:
print("you have already used it")
else:
if guess in correct:
print("You gussed one word correctly\n")
used.append(guess)
for i in range(len(correct)):
if guess==correct[i]:
new=new+guess
else:
new=new+so_far
so_far=new
else:
used=used.append(guess)
wrong=wrong+1
【问题讨论】:
标签: python python-2.7