mardi 9 janvier 2018

How can I run a python file in another python file?

Hey there I'm new to these forums so not entirely sure how it all works. I was doing my GCSE controlled assessment but it's been cancelled so I am allowed to ask for help. My teacher reccomended StackOverflow. The program I want to make opens a difficulty chooser program and opens a file already pre-loaded with the code needed to run a test. That file then takes questions stored in an external file and runs them inthe program. How do I run a python program within a program? So basically the question file opens a notepad file with the question in it and runs the test. I want to be able to open and run the test within a separate program which is the difficulty chooser.

File used to run questions:

    file = open("easyhistory1.txt", "r")
    print(file.readline())
    file.close

    question_1 = input("Was it in 1066 or 1966?: ")
    time.sleep(2)
    if question_1 == '1066':
        print("You are correct!")
        score = score + 1
        print("You're score is....")
        print(score)
    else:
        print("Sorry, that's wrong it was 1066.")
        score = score + 0
        print("You're score is....")
        print(score)
    time.sleep(1)
    print("")

Thanks

Aucun commentaire:

Enregistrer un commentaire