我有这个代码:
# -*- coding: utf-8 -*-
import random
import os, glob
guessesTaken = 325
ha=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 <10000 and ha<6:
print('Take a guess.') # There are four spaces in front of print.
guess = raw_input()
guess = int(guess)
guessesTaken = guessesTaken - 25
ha = ha+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)
ha = str(ha)
print('Good job, ' + name + '! You guessed my number in ' + ha + ' guesses!')
xa=len(name)
f='f'
with open("f", "a") as myfile:
myfile.write('name')
myfile.write(': ')
myfile.write(name)
myfile.write(' ')
if len(name)==1:
myfile.write(25 *' ')
if len(name)==2:
myfile.write(24 *' ')
if len(name)==3:
myfile.write(23 *' ')
if len(name)==4:
myfile.write(22 *' ')
if len(name)==5:
myfile.write(21 *' ')
if len(name)==6:
myfile.write(20 *' ')
if len(name)==7:
myfile.write(19 *' ')
if len(name)==8:
myfile.write(18 *' ')
if len(name)==9:
myfile.write(17* ' ')
if len(name)==10:
myfile.write(16*' ')
if len(name)==11:
myfile.write(15*' ')
if len(name)==12:
myfile.write(14*' ')
if len(name)==13:
myfile.write(13*' ')
if len(name)==14:
myfile.write(12*' ')
if len(name)==15:
myfile.write(11*' ')
if len(name)==16:
myfile.write(10*' ')
if len(name)==17:
myfile.write(9*' ')
if len(name)==18:
myfile.write(8*' ')
if len(name)==19:
myfile.write(7*' ')
if len(name)==20:
myfile.write(6*' ')
if len(name)==21:
myfile.write(5*' ')
if len(name)==22:
myfile.write(4*' ')
myfile.write('score')
myfile.write(': ')
myfile.write(guessesTaken)
myfile.write('\n\n')
with open(f) as myfile:
print myfile.read()
我想看起来像:
1.name score
2.name score
3.name score
。. . . . .
我不知道如何在名称前枚举。
我想像记录一样对分数进行排序。感谢您的帮助。