I2P- Summative- Quiz

Day 1:

The code working Video: 

I tried something different for the video, and sort of summed up the main points of the blog post down below. I did an audio recording above it trying to explain the code, as well as to show how the code works.

Day 2+3 reflection:

Step by step explanation of the code:

varglobal=0

def function_startagain ():
    startagain= input (print("Do you want to start the quiz again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1

The first part of the code was defining the global variables. Global variables are extremely helpful, especially when you want to break the code throughout (so this code can be used in any situation, and it will be able to break the code, and start the game again. It is extremely helpful throughout the game, when someone loses ( as it helps to ask the user whether or not they would like to restart the game.

def funct_game ():
    vbeginning= input("This is the international trivia competition. Your categories are as follows"
                      "\n 1. Animals"
                      "\n 2. General Trivia")
    while vbeginning!= "1" or "2":
        if vbeginning == "1":
            vstart= input("Are you ready to begin on your topic: Animals")
            if vstart=="yes":
                print ("Let's get started!")
                vquestion1= input ("Starting a little easy. Your first question is, I have four legs but no tail. "
                                   "\n Usually I am heard only at night. What am I? "
                                   "\n Your options are: "
                                   "\n 1. A monkey "
                                   "\n 2. A cat "
                                   "\n 3. A ladybird"
                                   "\n 4. A frog ")
                if vquestion1 == "4" :
                    print ("Good Job! You are correct! ")
                    vint= (18)
                    vguess= int(input("Next question  is a little bit more challenging."
                                        "\n Your question is How many species of penguins are there?"
                                        "\n the answer is between 10-20"))

 

This next part is a sample of the code throughout the first part of the game. This part uses multiple if and else statements in order to perform the task at hand. I used this as a basis beginning, before adventuring off to other parts of code. The if and else statements are quite easy to follow, as they simply ask the user to input their answer. If the answer is correct, then there will be the next question

Pros:

This method I found was the easiest to code, and made the most sense in my head. I could understand everything, and was more comfortable with this method.

Cons:

This was not the most effficient method in order to perform the task at hand. There are other methods that I tested out that worked better then this one, so I used this mostly as a foundation, as well as a comparison to other types of the code.

Syntax errors that were faced.

Throughout the code, I actually faced quite a few syntax errors. This was because when doing the game based on if and else statements, the indents got quite messy after a while. It was especially hard because some of the indents were halfway indents, so when trying to line up the else statements, it became really hard.

Another syntax that i faced was definitely making the decision of using if variable != “” or if variable == “” . In some places one worked better then the other, and sometimes there were cases where the other worked and one didn’t. I am still researching into why this occurred, but have made some conclusions that the code was just more sensitive in some places then others.

Screen Shot 2016-11-19 at 7.34.07 AM

vguess= int(input("Next question  is a little bit more challenging."
                                        "\n Your question is How many species of penguins are there?"
                                        "\n the answer is between 10-20"))
                    while vguess!= vint:
                        if vguess >  vint:
                            print("The number is lower")
                            vguess=int(input("Guess a number frm 10-20"))
                        if vguess < vint:
                            print("The number is higher ")
                            vguess =int(input("Guess a number frm 10-20"))

For this question in the animal section, I knew I wanted to give the user a guessing sort of answer choice instead of multiple choice. It became quite fun in order to solve it , because it was interesting to apply the guess the number game to the summative piece. I suddenly realised that all the code that we have done prior to the summative could actually be incorporated in some manner. Besides using the guess the number game, I also incorporated some of the guess the word game, and used the formative as a check and reference.

The guess the name was used for the last question of the animal section. I thought that it was quite interesting to see how it could be applied to making the user guess the answer instead of multiple choice.

 if vquestion6 != "Shadow":
                                            print ("It's something that trails behind you")
                                            vgiveup= input (" Do you want to give up?")
                                            if vgiveup == "no" or "No":
                                                vquestionafterprompt= input ("Try again!"
                                                                             "\n 1. Shadow"
                                                                             "\n 2. Sharpie "
                                                                             "\n 3. Water "
                                                                             "\n 4. Trick question")
                                                if vquestionafterprompt!="1":
                                                    print ("Too bad, you lose")
                                                    print(function_startagain())
                                                else:
                                                    print ("Good job!You have beaten the quiz! ")
                                                    print (function_startagain())

Furthermore, I learnt more about how to use text files. i have never used text files before, so I had to do some prior research before hand to get some ideas on what this would look like:

text_file= open ("write_it.txt","w")
lines= input("What is your name")
if lines=="1":
    print ("Hi")

text_file=open ("write_it.txt", "r")
print (text_file.read())
text_file.close()

This is a small piece of code showcasing what a text file would look like. I thought that maybe I could write an entire quiz as a text file and store it there, then use the text file and print it. I would also like to see if i could use it to store the count, as well as their name and age.

Pseudo code:

Pseudo/brainstorm

Here is the pdf version of my pseudo code, and brain frame. At the start of the game I was skeptical of making this, because I wasn’t exactly sure how and where to start. However, after a few tries, I managed to get started, and everything fell into place.

Use of the brain-frame:

I use the brain-frame to help me to organise all of the material given to me, and to ensure that I am remembering to include everything into my code. It sort of acts as a checklist for everything. I find the brain-frame convenient to use, because it sort of gives me an idea of the layout of everything, as well as some key points that I need to remember throughout. Through making the brain frame, it allowed me to make a skeleton of the entire game at hand, so that I could visualise what exactly needed to be coded.

Brain-frame vs pseudo code:

After making the brain frame, I decided to compare and contrast the advantages of each of the starting templates, and which ones would’ve been more helpful. I personally prefer to use the brain frame, because putting it in order of pseudo code can be quite a large task for me to do, and I feel like I can visualise things better when I have all the things I need to include in a brain frame, and for me to order it in that manner. Through the brain frame, it allowed me to think openly, and move around things in the correct order.

Reflection:

Overall, today’s class went really well, and I learnt a lot about the different ways to make a quiz. I tried multiple different methods to get the hand at both if and else statements, as well as the use of functions. Before this activity, I still wasn’t as comfortable with using the functions, but after, I think I am starting to get used to the entire use. Through this activity, I could also start to see which one of the codes were more effective, and the importance of planning before hand.  I also realised that at the beginning I was trying to do too many things at once, which made the entire process just confusing, rather than helpful. I’m excited to start to learn more about text files at home, and apply it next class.

One other thing that I found really helpful, was to keep trying throughout the process, and to try to make sample codes first of the process I want to try out.

def funct_vquestion11 ():
 vquestion11 = input ("What's your favorite day?")
 if vquestion11== "1" :
 print (funct_vquestion12())
def funct_vquestion12 ():
 vquestion12= input ("Good job! What's your fav food?")
 if vquestion12 == "2":
 print (funct_vquestion13())
def funct_vquestion13 ():
 vquestion13= input ("Good job! What's the capital of Japan")
def funct_vquestion14 ():
 vquestion14= ("1+2=?")

Since I was still not familiar with the function use, I decided to test it out the functions with a small bit of code first. So I tested it out with the code above ( the answers don’t really make sense for the questions, but this was just trial, so I wasn’t concerned about the logic of the question, but more so, the format, and the logic of the code.) There are many ways to apply functions to the code at hand, but I tried to use it by defining all my functions, and relating two questions at a time, and putting that into one large code at the end. I tried different techniques, but this one seemed like it was working the most, and I could logically follow it the best.

My plan for next time:

1. Incorporate the sample function part into the code

2. Incoporate the text file into the code

3. Write more about the text file used

4. productivity and use  of time?

Day 2:

Today i worked on getting the text file working, as well as getting the function game to work well.  The text file took a long time for me to work out, especially since I have never worked with the text files before. It was a fun challenge to solve all the different errors that I encountered along the way, and it was satisfying to be successful in the end.

Functions game:

For the functions part I tried something different from most of the other codes that I have worked with the functions. For example, in a lot of my previous codes I used the function without anything else, just the function  of print. This time, I tried to make the functions related to every other function. So the function 1, would only print if the function before that ( the user input the right answer for the previous function) I had tested with a small piece of code last time, and it worked, so for this part I modelled after the sample code, and tried to make the code for the second part of the game. Some of the errors that I faced was that I couldn’t put the if and else statements all into one function. What I mean by this is that I envisioned one of the functions to have if and else statements throughout, and to define my functions underneath that. However, this didn’t work and jammed up the entire code, so it was better to do it part by part, and to only do it per two functions.

Overall, I think that this way of doing the code was easier and took up less code then the other methods. It seemed to take up the least amount of code, or the same amount as the text file method.

This was the testing part that I modelled after to get the rest of my code to work for this part of the game.

def funct_vquestion12 ():
    vquestion12= input ("Good job! What's your fav food?")
    if vquestion12 == "2":
        print (funct_vquestion13())

def funct_vquestion13 ():
    vquestion13= input ("Good job! What's the capital of Japan")

def funct_vquestion14 ():
    vquestion14= ("1+2=?")

By using this, I modelled the rest of my code for this part of the game. Basically, I was able to take this small part of code, and follow that example to make the entire second game.

Text files:

For the third game, I used the text files. Text files was something that we haven’t done before, so it was interesting to see how we could use them in the game. Basically text files can be used to store text, instead of writing it out onto lines. It’s easy storage for large pieces of text, that can be called later throughout your code.

For the game that I made, the text files became good to store the entire quiz, and I would call certain lines up for each question. I had some problems here, especially since I hadn’t worked with text files before. I wanted to call a certain amount of lines, and had a long trial and error process in order to try to figure out how to do it. Before this however, I had to learn how to create text files, open them, import them, and the different functions that the text files could provide. Once I found out how to use the text file, (open, read, and write) I then moved onto brainstorming how this could be helpful for the game. I debated on using this for the count function. So the text file would store the score that the user had. I then also realised you could use this text file to store names, but ended up going with the function of creating  an entire game through the text file.

How this worked was that the text file was created, and I could write my entire quiz through the text file. Then, in my main code, I could call up certain lines of the text from the text file. For this part I had to use the for i in range function which allowed me to call certain lines of code. This was hard at first to figure out, because I wasn’t using the for loop, and instead used just range. This printed out the code in a very weird way, with \n and all the choices on one line. It was okay, but it didn’t print in the way that I wished it did. So I continued to work on the code, and find a better way to complete the same task.

print ( "Good job! ")
                vcounter=vcounter+1
print ("Your score is:",vcounter ,"!")
                for i in range (7,14):
                    print (text_file.readline())
                vquestion21 = input ("Input 1,2,3, or 4")
                if vquestion21!= "1":
                    print ("Tough luck! Better luck next time!")
                    print ("Your final score is:",vcounter ,"!")
                    print (function_startagain())

Above is a sample part of the code using the text file. I had to research some of the specific commands for text files, which included the read lines function, and calling the text file, and closing it. It was interesting to see how intuitive the code was, and how I could incorporate if and else statements throughout the code as well.

In terms of which code is better, and more efficient (text file, if and else statements, or functions) I believe that the text files or the functions were one of the most efficient pieces of code. The text file definitely proved to be effective, especially since it meant that my code wasn’t going to be filled with lines of text. The functions put everything before hand, and outside of the main part of the code, so inside the actual game  function it was only one line of code since all my functions were inter-related. The if and else statements took up the most lines of code, and were the least effective throughout. In order to code the same thing, the functions and text  files took up less than half the amount of code, to create the same game.

Testing document:

In order to keep track of all the errors that I made throughout the code, we created something called the testing document. This allowed us to reference previous errors we fixed to solve new errors, and acted like a log of progress as well. This I imagine, will be very helpful in the long run, and can help us with remembering previous errors we have done, and fix them.’

https://docs.google.com/spreadsheets/d/e/2PACX-1vROe4ufEt_ccEKi27YnxmlKWtYU9VM-HFuy91dY2gWpfU3tkbxudMwQC-QBroo6NO09wdHJSzaIVbMq/pubhtml

Overall, I feel like the entire project was not only fun, and interesting, but also one that was challenging and at times hard. Comparing it to the formative is very hard, especially since the approach to the code was very different for each one. I was, however, able to reference some of the code that I had previously. I found it hard but fun to incorporate the text files, and feel as if throughout this project I have become more confident with my coding abilities. Furthermore, i feel like the coding language has become more familiar to me, and I can now think and envision what the code would look like.Final Reflection:

Code:

Day 1 code:

varglobal=0
def function_startagain ():
    startagain= input (print("Do you want to start the quiz again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1
#define functions
def funct_vquestion11 ():
    vquestion11 = input ("What's your favorite day?")
    if vquestion11== "1" :
        print (funct_vquestion12())

def funct_vquestion12 ():
    vquestion12= input ("Good job! What's your fav food?")
    if vquestion12 == "2":
        print (funct_vquestion13())

def funct_vquestion13 ():
    vquestion13= input ("Good job! What's the capital of Japan")

def funct_vquestion14 ():
    vquestion14= ("1+2=?")


def funct_game ():
    vbeginning= input("This is the international trivia competition. Your categories are as follows"
                      "\n 1. Animals"
                      "\n 2. General Trivia")
    while vbeginning!= "1" or "2":
        if vbeginning == "1":
            vstart= input("Are you ready to begin on your topic: Animals")
            if vstart=="yes":
                print ("Let's get started!")
                vquestion1= input ("Starting a little easy. Your first question is, I have four legs but no tail. "
                                   "\n Usually I am heard only at night. What am I? "
                                   "\n Your options are: "
                                   "\n 1. A monkey "
                                   "\n 2. A cat "
                                   "\n 3. A ladybird"
                                   "\n 4. A frog ")
                if vquestion1 == "4" :
                    print ("Good Job! You are correct! ")
                    vint= (18)
                    vguess= int(input("Next question  is a little bit more challenging."
                                        "\n Your question is How many species of penguins are there?"
                                        "\n the answer is between 10-20"))
                    while vguess!= vint:
                        if vguess >  vint:
                            print("The number is lower")
                            vguess=int(input("Guess a number frm 10-20"))
                        if vguess < vint:
                            print("The number is higher ")
                            vguess =int(input("Guess a number frm 10-20"))
                    if vint == vguess:
                        print("This is the right number! Good job")
                        vquestion3= input("What jumps when it walks and sits when it stands?"
                                              "\n 1. Kangaroo "
                                              "\n 2. Ladybug "
                                              "\n 3. Dandelion "
                                              "\n 4. Lion ")
                        if vquestion3=="1":
                            print ("Good job! You're on a roll!")
                            vquestion4= input ("I had no fathers, only a grandfather. I shall bear"
                                                   "\n no sons, only daughters. What am I? "
                                                   "\n 1. Ant "
                                                   "\n 2. Bee "
                                                   "\n 3. Carpet "
                                                   "\n 4. Dolphin")
                            if vquestion4== "2" :
                                print("Good job! You are doing well! Only a few more questions!")
                                vquestion5=input ("What is the easter bunny's favorite type of dance?"
                                                      "\n 1. Hip hop"
                                                      "\n 2. Any dance"
                                                      "\n 3. K-pop"
                                                      "\n 4. Canto-pop")
                                if vquestion5== "1" :
                                     print ("You've almost beaten the quiz!")
                                     vquestion6= input("What part of a bird isn't in the sky and can swim but not get wet?"
                                                        "\n the correct answer starts with s, ends with w, and has 6 letters.")
                                     if vquestion6 != "Shadow":
                                            print ("It's something that trails behind you")
                                            vgiveup= input (" Do you want to give up?")
                                            if vgiveup == "no" or "No":
                                                vquestionafterprompt= input ("Try again!"
                                                                             "\n 1. Shadow"
                                                                             "\n 2. Sharpie "
                                                                             "\n 3. Water "
                                                                             "\n 4. Trick question")
                                                if vquestionafterprompt!="1":
                                                    print ("Too bad, you lose")
                                                    print(function_startagain())
                                                else:
                                                    print ("Good job!You have beaten the quiz! ")
                                                    print (function_startagain())

                                            else:
                                                print (" You gave up! Too bad, you lose! ")
                                                print (function_startagain())
                                     else:
                                         print ("Good job!You have beaten the quiz!")
                            else:
                                print ("Tough luck, you lose!")
                                print (function_startagain())
                        else:
                            print (" Too bad, you lose! ")
                            print (function_startagain())
                else :
                    print ("Incorrect! You are out!")
                    print (function_startagain())

            else:
                print (function_startagain())

                #start of game two
if vbeginning=="2":
            print(funct_vquestion11())


print (funct_game())

Day 2 code

varglobal=0
def function_startagain ():
    startagain= input (print("Do you want to start the quiz again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1
#define functions
def funct_vquestion11 ():
    vquestion11 = input ("Which number is the only even prime? "
                         "\n 1. 2 "
                         "\n 2. 3"
                         "\n 3. 4 "
                         "\n 4. 5")
    if vquestion11== "1" :
        print (funct_vquestion12())

    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion12 ():
    vquestion12= input ("Good job! Where's french fries from?"
                        "\n 1. France "
                        "\n 2. USA "
                        "\n 3. Germany "
                        "\n 4. Belgium")
    if vquestion12 == "4":
        print (funct_vquestion13())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())


def funct_vquestion13 ():
    vquestion13= input ("Good job! What's the capital of Japan"
                        "\n 1. Tokyo "
                        "\n 2. Nagasake "
                        "\n 3. Hokaido"
                        "\n 4. Germany")
    if vquestion13== "1":
        print (funct_vquestion14())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion14 ():
    vquestion14= input ("1+2=?"
                  "\n 1. 3 "
                  "\n 2. 4"
                  "\n 3. 5"
                  "\n 4. 6")
    if vquestion14=="1":
        print (funct_vquestion15 ())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion15():
    print ("Good job! You did really well!")
    print ( function_startagain())


#this should be used for the second part of the game
def funct_game ():
    vcounter=0
vbeginning= input("This is the international trivia competition. Your categories are as follows"
                      "\n 1. Animals"
                      "\n 2. General Trivia"
                      "\n 3. Random")
    while vbeginning!= "1" or "2" or "3":
        if vbeginning == "1":
            vstart= input("Are you ready to begin on your topic: Animals press 1 to begin")
            if vstart=="1":
                print ("Let's get started!")
                vquestion1= input ("Starting a little easy. Your first question is, I have four legs but no tail. "
                                   "\n Usually I am heard only at night. What am I? "
                                   "\n Your options are: "
                                   "\n 1. A monkey "
                                   "\n 2. A cat "
                                   "\n 3. A ladybird"
                                   "\n 4. A frog ")
                if vquestion1 == "4" :
                    print ("Good Job! You are correct! ")
                    vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                    vint= (18)
                    vguess= int(input("Next question  is a little bit more challenging."
                                        "\n Your question is How many species of penguins are there?"
                                        "\n the answer is between 10-20"))


                    while vguess!= vint:
                        if vguess >  vint:
                            print("The number is lower")
                            vguess=int(input("Guess a number frm 10-20"))
                        if vguess < vint:
                            print("The number is higher ")
                            vguess =int(input("Guess a number frm 10-20"))
                    if vint == vguess:
                        print("This is the right number! Good job")
                        vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                        vquestion3= input("What jumps when it walks and sits when it stands?"
                                              "\n 1. Kangaroo "
                                              "\n 2. Ladybug "
                                              "\n 3. Dandelion "
                                              "\n 4. Lion ")
                        if vquestion3=="1":
                            print ("Good job! You're on a roll!")
                            vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                            vquestion4= input ("I had no fathers, only a grandfather. I shall bear"
                                                   "\n no sons, only daughters. What am I? "
                                                   "\n 1. Ant "
                                                   "\n 2. Bee "
                                                   "\n 3. Carpet "
                                                   "\n 4. Dolphin")
                            if vquestion4== "2" :
                                print("Good job! You are doing well! Only a few more questions!")
                                vquestion5=input ("What is the easter bunny's favorite type of dance?"
                                                      "\n 1. Hip hop"
                                                      "\n 2. Any dance"
                                                      "\n 3. K-pop"
                                                      "\n 4. Canto-pop")
                                vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                                if vquestion5== "1" :
                                     print ("You've almost beaten the quiz!")
                                     vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                                     vquestion6= input("What part of a bird isn't in the sky and can swim but not get wet?"
                                                        "\n the correct answer starts with s, ends with w, and has 6 letters.")
                                     if vquestion6 != "Shadow":
                                            print ("It's something that trails behind you")
                                            vgiveup= input (" Do you want to give up?")
                                            if vgiveup == "no" or "No":
                                                vquestionafterprompt= input ("Try again!"
                                                                             "\n 1. Shadow"
                                                                             "\n 2. Sharpie "
                                                                             "\n 3. Water "
                                                                             "\n 4. Trick question")
                                                if vquestionafterprompt!="1":
                                                    print ("Too bad, you lose")
                                                    print(function_startagain())
                                                else:
                                                    print ("Good job!You have beaten the quiz! ")

                                                    print ("Your final score is:",vcounter ,"!")
                                                    print (function_startagain())

                                            else:
                                                print (" You gave up! Too bad, you lose! ")
                                                print ("Your final score is:",vcounter ,"!")
                                                print (function_startagain())
                                     else:
                                         print ("Good job!You have beaten the quiz!")
                                         print ("Your final score:",vcounter ,"!")
                                         print (function_startagain())
                            else:
                                print ("Tough luck, you lose!")
                                print ("Your final score is:",vcounter ,"!")
                                print (function_startagain())
                        else:
                            print (" Too bad, you lose! ")
                            print ("Your final score is:",vcounter ,"!")
                            print (function_startagain())
                else :
                    print ("Incorrect! You are out!")
                    print ("Your final score is:",vcounter ,"!")
                    print (function_startagain())

            else:
                print (function_startagain())

                #start of game two
if vbeginning=="2":
            print(funct_vquestion11())


        if vbeginning =="3":
            text_file= open ("write_it.txt1", "r")
            for i in range (0,5):
                print (text_file.readline())
            vquestion20= input ("Input 1, 2, 3, or 4")
            if vquestion20 != "1":varglobal=0
def function_startagain ():
    startagain= input (print("Do you want to start the quiz again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1
#define functions
def funct_vquestion11 ():
    vquestion11 = input ("Which number is the only even prime? "
                         "\n 1. 2 "
                         "\n 2. 3"
                         "\n 3. 4 "
                         "\n 4. 5")
    if vquestion11== "1" :
        print (funct_vquestion12())

    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion12 ():
    vquestion12= input ("Good job! Where's french fries from?"
                        "\n 1. France "
                        "\n 2. USA "
                        "\n 3. Germany "
                        "\n 4. Belgium")
    if vquestion12 == "4":
        print (funct_vquestion13())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())


def funct_vquestion13 ():
    vquestion13= input ("Good job! What's the capital of Japan"
                        "\n 1. Tokyo "
                        "\n 2. Nagasake "
                        "\n 3. Hokaido"
                        "\n 4. Germany")
    if vquestion13== "1":
        print (funct_vquestion14())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion14 ():
    vquestion14= input ("1+2=?"
                  "\n 1. 3 "
                  "\n 2. 4"
                  "\n 3. 5"
                  "\n 4. 6")
    if vquestion14=="1":
        print (funct_vquestion15 ())
    else:
        print ("Incorrect! You are out!")
        print (function_startagain())

def funct_vquestion15():
    print ("Good job! You did really well!")
    print ( function_startagain())


#this should be used for the second part of the game
text_file = open ("write_it.txt", "w")

text_file.write = ("You have done really well so far in the game!")
text_file.close ()
text_file= open ("write_it.txt", "r")
print (text_file.read ())
text_file.close

def funct_game ():
    vcounter=0
vbeginning= input("This is the international trivia competition. Your categories are as follows"
                      "\n 1. Animals"
                      "\n 2. General Trivia"
                      "\n 3. Random")
    while vbeginning!= "1" or "2" or "3":
        if vbeginning == "1":
            vstart= input("Are you ready to begin on your topic: Animals press 1 to begin")
            if vstart=="1":
                print ("Let's get started!")
                vquestion1= input ("Starting a little easy. Your first question is, I have four legs but no tail. "
                                   "\n Usually I am heard only at night. What am I? "
                                   "\n Your options are: "
                                   "\n 1. A monkey "
                                   "\n 2. A cat "
                                   "\n 3. A ladybird"
                                   "\n 4. A frog ")
                if vquestion1 == "4" :
                    print ("Good Job! You are correct! ")
                    vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                    vint= (18)
                    vguess= int(input("Next question  is a little bit more challenging."
                                        "\n Your question is How many species of penguins are there?"
                                        "\n the answer is between 10-20"))


                    while vguess!= vint:
                        if vguess >  vint:
                            print("The number is lower")
                            vguess=int(input("Guess a number frm 10-20"))
                        if vguess < vint:
                            print("The number is higher ")
                            vguess =int(input("Guess a number frm 10-20"))
                    if vint == vguess:
                        print("This is the right number! Good job")
                        vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                        vquestion3= input("What jumps when it walks and sits when it stands?"
                                              "\n 1. Kangaroo "
                                              "\n 2. Ladybug "
                                              "\n 3. Dandelion "
                                              "\n 4. Lion ")
                        if vquestion3=="1":
                            print ("Good job! You're on a roll!")
                            vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                            vquestion4= input ("I had no fathers, only a grandfather. I shall bear"
                                                   "\n no sons, only daughters. What am I? "
                                                   "\n 1. Ant "
                                                   "\n 2. Bee "
                                                   "\n 3. Carpet "
                                                   "\n 4. Dolphin")
                            if vquestion4== "2" :
                                print("Good job! You are doing well! Only a few more questions!")
                                vquestion5=input ("What is the easter bunny's favorite type of dance?"
                                                      "\n 1. Hip hop"
                                                      "\n 2. Any dance"
                                                      "\n 3. K-pop"
                                                      "\n 4. Canto-pop")
                                vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                                if vquestion5== "1" :
                                     print ("You've almost beaten the quiz!")
                                     vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                                     vquestion6= input("What part of a bird isn't in the sky and can swim but not get wet?"
                                                        "\n the correct answer starts with s, ends with w, and has 6 letters.")
                                     if vquestion6 != "Shadow":
                                            print ("It's something that trails behind you")
                                            vgiveup= input (" Do you want to give up?")
                                            if vgiveup == "no" or "No":
                                                vquestionafterprompt= input ("Try again!"
                                                                             "\n 1. Shadow"
                                                                             "\n 2. Sharpie "
                                                                             "\n 3. Water "
                                                                             "\n 4. Trick question")
                                                if vquestionafterprompt!="1":
                                                    print ("Too bad, you lose")
                                                    print(function_startagain())
                                                else:
                                                    print ("Good job!You have beaten the quiz! ")

                                                    print ("Your final score is:",vcounter ,"!")
                                                    print (function_startagain())

                                            else:
                                                print (" You gave up! Too bad, you lose! ")
                                                print ("Your final score is:",vcounter ,"!")
                                                print (function_startagain())
                                     else:
                                         print ("Good job!You have beaten the quiz!")
                                         print ("Your final score:",vcounter ,"!")
                                         print (function_startagain())
                            else:
                                print ("Tough luck, you lose!")
                                print ("Your final score is:",vcounter ,"!")
                                print (function_startagain())
                        else:
                            print (" Too bad, you lose! ")
                            print ("Your final score is:",vcounter ,"!")
                            print (function_startagain())
                else :
                    print ("Incorrect! You are out!")
                    print ("Your final score is:",vcounter ,"!")
                    print (function_startagain())

            else:
                print (function_startagain())

                #start of game two
if vbeginning=="2":
            print(funct_vquestion11())


        if vbeginning =="3":
            text_file= open ("write_it.txt1", "r")
            for i in range (0,5):
                print (text_file.readline())
            vquestion20= input ("Input 1, 2, 3, or 4")
            if vquestion20 != "1":
                print ("Incorrect! You are out!")
                print ("Your final score is:",vcounter ,"!")
                print (function_startagain())

            else:
                print ( "Good job! ")
                vcounter=vcounter+1
print ("Your score is:",vcounter ,"!")
                for i in range (7,14):
                    print (text_file.readline())
                vquestion21 = input ("Input 1,2,3, or 4")
                if vquestion21!= "1":
                    print ("Tough luck! Better luck next time!")
                    print ("Your final score is:",vcounter ,"!")
                    print (function_startagain())
                else:
                    print ("Good job!")
                    vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                    for i in range (15,21):
                        print (text_file.readline())
                    vquestion23= input ("Input 1,2,3, or 4")
                    if vquestion23!= "4":
                        print ("Better luck next time! ")
                        print ("Your final score is:",vcounter ,"!")
                        print (function_startagain())
                    else:
                        print ("Good Job!")
                        vcounter=vcounter+1
print ("Your score now is",vcounter ,"!")
                    for i in range (22,28):
                        print (text_file.readline())
                    vquestion24= input ("Input 1,2,3, or 4")
                    if vquestion24!= "1":
                        print ("Better luck next time! ")
                        print ("Your score is:",vcounter ,"!")
                        print (function_startagain())
                    else:
                        print ("Good Job!")
                        vcounter=vcounter+1
print (vcounter)
                        break
text_file.close()


print (funct_game())


Citations:
Ivoz. “OpenTechSchool.” OpenTechSchool – Working With Text Files. OpenTechSchool, 2013-2014. Web. 22 Nov. 2016.
Pythonforbeginners. “Reading and Writing Files in Python.” Python For Beginners. TreeHouse, 8 July 2013. Web. 22 Nov. 2016.

Stack Overflow. “Python – Read File from and to Specific Lines of Text.” Stack Overflow. StackExchange, 16 Sept. 2011. Web. 22 Nov. 2016.

 

 


 

Leave a Reply