代码是:
import pickle
import random
guessesTaken = 0
print('Hello! What is your name?')
name = raw_input()
number = random.randint(1, 20)
print('Well, ' + name + ', I am thinking of a number between 1 and 20.')
while guessesTaken < 6:
print('Take a guess.') # There are four spaces in front of print.
guess = raw_input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.') # There are eight spaces in front of print.
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + name + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
clasament= 'clasament.data'
f=open(clasament, 'wb')
pickle.dump(name, f)
我想做一个像这样的顶级:
nameguessesTaken
nameguessesTaken
....
我只能让名字出现,如果你再次玩游戏,名字会刷新。
我收到此错误。回溯(最近一次调用):文件“/home/catalin/guessnumber.py”,第 44 行,名称,dct.items()中的猜测:AttributeError:'str' 对象没有属性'项目'