私はこのコードを持っています:
# -*- coding: utf-8 -*-
import random
import os, glob
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.')
guess = raw_input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.')
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!')
xa=len(name)
#has= str(name) + ' ' + str(guessesTaken) +
f='toplevel.data'
with open("f", "a") as myfile:
myfile.write('name')
myfile.write(': ')
myfile.write(name)
myfile.write(' ')
if len(name)>7:
myfile.write((xa-7)*' ')
elif len(name)==7:
myfile.write(40*' ')
else:
myfile.write((7-xa)*' ')
myfile.write('score')
myfile.write(': ')
myfile.write(guessesTaken)
次の問題があります。このコードの最後に、内容を含む toplevel.data を出力したいのですが、これは行いません。
ご協力ありがとう御座います。
#('gfdsgdgdfgdfgdfgdfgdfgsdgdfgdfgdfgdfgdfgfdgdfgdsfgfdgdfgdfgdfgdfgdfgdfgdfgdf')