Python Questions

Hello Guys.
This is a topic where users can come and write about anything python-related--if they need help with something, or want to show off their skills--this is the place.
So, let me get the ball rolling with a question:
How do you write a high score to a file and return it in some way within a program? Here is my code below. I politely ask that you tell me a way I could do it, but don't put code in for me. Code:
import random
def file_question():
    filename=raw_input("what is the name of the file you want to open?")
    return filename
   
filename = file_question()

def open_file(filename):
    try:
        infile = open(filename, "rb")
    except:
        infile = open('C:\\Users\\234265\\Desktop\\'+filename, 'rb')

   
    trivia={}
    counter=1
    for line in infile:
        if counter%2=1:
            question=line
        elif counter%2=0
            answer = line
        trivia[question]=answer
    infile.close()
    return trivia

trivia = open_file(filename)

def ask_questions()
    counter=0
    questions=trivia.keys()
    random.shuffle(questions)
    for question in questions:
        guess=input(question)
            if guess=trivia[question]
                counter+=1
        counter=str(counter)
        print "You got "+counter +"out of "+len(questions) +&quo t;right."
ask_questions()
def play_again():
    asker=raw_input("would you like to play again?")
    if asker=="y":
        file_question()
        ask_questions()
    elif asker=="n":
        print "have a nice day."
        break

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : superb via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : superb via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : raven via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : brian . kurosawa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : superb via Audiogames-reflector

Reply via email to