Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
8.5 kB
2
Indexable
Never
#questions and answers (with slight adaptation) retrieved from https://www.theguardian.com/tv-and-radio/ng-interactive/2020/sep/12/who-wants-to-be-a-millionaire-jackpot-questions-quiz-yourself
#My TA Nienke Dekkema has checked my code and says it is correct, however there is a bug in Spyder that sometimes prints messages in an incorrect order, leaving my code to get stuck
import io #imports input/output functions

file = io.open('scoreboard.txt', 'a') #opens file scoreboard.txt and gives appending permission
name = input("Please give your name")

welcome_msg = "Welcome " + name + " to Who Wants to be a Millionaire! You have 2 jokers that take away 2 wrong answers. Any additional joker use is penalized with deducting one step per additional use from the prizelader"

q1= "In the UK, the abbreviation NHS stands for National what Service?"
a1= ["Humanity", "Health", "Honour", "Household"] 
q2= "Which Disney character famously leaves a glass slipper behind at a royal ball?"
a2= ["Pocahontas", "Sleeping Beauty", "Cinderella", "Elsa"] 
q3= "What name is given to the revolving belt machinery in an airport that delivers checked luggage from the plane to baggage reclaim?"
a3= ["Hangar", "Terminal", "Concourse", "Carousel"] 
q4= "Which of these brands was chiefly associated with the manufacture of household locks?"
a4= ["Phillips", "Flymo", "Chubb", "Ronseal"]
q5= "The hammer and sickle is one of the most recognisable symbols of which political ideology?"
a5= ["Republicanism", "Communism", "Conservatism", "Liberalism"] 
q6= "Which toys have been marketed with the phrase “robots in disguise”?"
a6= ["Bratz Dolls", "Sylvanian Families", "Hatchimals", "Transformers"]
q7= "What does the word loquacious mean?"
a7= ["Angry", "Chatty", "Beautiful", "Shy"] 
q8= "Obstetrics is a branch of medicine particularly concerned with what?"
a8= ["Childbirth", "Broken bones", "Heart conditions", "Old age"]
q9= "In Doctor Who, what was the signature look of the fourth Doctor, as portrayed by Tom Baker?"
a9= ["Bow-tie, braces and tweed jacket","Wide-brimmed hat and extra long scarf", "Pinstripe suit and trainers", "Cape, velvet jacket and frilly shirt" ] #b
q10= "Which of these religious observances lasts for the shortest period of time during the calendar year?"
a10= ["Ramadan", "Diwali", "Lent", "Hanukkah"] 
q11= "At the closest point, which island group is only 50 miles south-east of the coast of Florida?"
a11= ["Bahamas", "US Virgin Islands", "Turks and Caicos Islands", "Bermuda"] 
q12= "Construction of which of these famous landmarks was completed first?"
a12= ["Empire State Building", "Royal Albert Hall", "Eiffel Tower", "Big Ben Clock Tower"] 
q13= "Which of these cetaceans is classified as a “toothed whale”?"
a13= ["Gray whale", "Minke whale", "Sperm whale", "Humpback whale"] 
q14= "Who is the only British politician to have held all four “Great Offices of State” at some point during their career?"
a14= ["David Lloyd George",  "Harold Wilson", "James Callaghan", "John Major"]
q15= "Is Bonnie the best?"
a15= ["No, cats are better", "Yes", "Only in the winter", "No, the neighbours dog is better"]
List_of_questions = [q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15]
List_of_answers = [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15]
List_of_money = [0, 50, 100, 200, 300, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 125000, 500000, 1000000] #0 needed, otherwise choosing 6 at first question leads to winning the million
correct_answers = ["2", "3", "4", "3", "2", "4", "2", "1", "2", "2", "1", "4", "3", "3", "2"] #strings, so that no answer can crash the code -> if it were int, any letter as answer would lead to an error
empty_list = [] #used for joker
qnr=-1 #starts at -1 so that I can increase qnr straight away in while loop, which is useful for continue in joker situations
joker=0
print(welcome_msg)

def joker_check(joker_amount, allowed):    #checks to see if joker has been used more than two times, which is then used to deduct prize money
    if joker_amount <= allowed:
        joker = 0
    else:
        joker = joker_amount - allowed
    return joker



while qnr <=13: #allows up to 15 executions
    qnr += 1
    print(List_of_questions[qnr])
    print(List_of_answers[qnr])   
    user_answer= input("Is the answer 1,2,3 or 4? If you want to use a joker, select 5. If you want to take the money, type 6")
    
    
        
    if user_answer == correct_answers[qnr]:
        print("Correct answer!")
        
    elif user_answer == "6": #code for cashout
            print("Congratulations " + name + " on winning " + str(List_of_money[qnr-joker_check(joker, 2)]) + "€") 
            file.writelines([name , "   ",  str(List_of_money[qnr-joker_check(joker, 2)]), "\n"]) 
            break
    
    elif user_answer == "5": #code for joker-option
            joker += 1
            empty_list = List_of_answers[qnr]
            if correct_answers[qnr] == "1" or correct_answers[qnr] == "4": #code executed when the correct answer is either 1 or 4, gets rid of options 2 and 3
                empty_list.pop(2) #gets rid of option 3
                empty_list.pop(1) #gets rid of option 2
                print("You have selected a joker. The remaining answers are: " + str(empty_list))
                new_user_answer= input("Is the answer 1 or 4?") #creates variable new_user_answer, to let user give an answer for previously asked question where joker was selected
                
                if new_user_answer == correct_answers[qnr]:
                    print("Correct answer!")
                    continue
                elif new_user_answer == "6":
                    print("Congratulations " + name + " on winning " + str(List_of_money[qnr-joker_check(joker, 2)]) + "€") #just removed a -1, should be right
                    file.writelines([name , "   ",  str(List_of_money[qnr-joker_check(joker, 2)]), "\n" ])
                    break
                else:
                    print("Wrong answer :(")
                    file.writelines([name , "   0" , "\n"])
                    break
                
            elif correct_answers[qnr] == "2" or correct_answers[qnr] == "3": #code executed when the correct answer is either 2 or 3, gets rid of options 1 and 4
                empty_list.pop(0) #gets rid of option 1
                empty_list.pop() #gets rid of option 4; could also use (2) in brackets, but () gets rid of last option anyways
                print("You have selected a joker. The remaining answers are: " + str(empty_list))
                new_user_answer= input("Is the answer 2 or 3?")
                
                if new_user_answer == correct_answers[qnr]:
                    print("Correct answer!")
                    continue
                elif new_user_answer == "6":
                    print("Congratulations " + name + " on winning " + str(List_of_money[qnr-joker_check(joker, 2)]) + "€") 
                    file.writelines([name , "   ", str(List_of_money[qnr-joker_check(joker, 2)]), "\n"])
                    break
                else:
                    print("Wrong answer :(")
                    file.writelines([name , "   0" , "\n"])
                    break
    else: #code if answer is unexpected(so not 1,2,3,4,5 or 6) or wrong
        print("Wrong answer :(")
        file.writelines([name, "   0", "\n"])
        break
         
if qnr == 14 and joker<3: #code if every question was correctly answered
    print("CONGRATULATIONS!!! " + name + ", YOU ARE A MILLIONAIRE!!!") #specific congratulations message if less than 3 jokers were used
    file.writelines([name, "  ",  str(List_of_money[qnr+1]), "\n"]) #qnr+1 because [15] needs to be reached
elif qnr == 14: 
    print("Congratulations on correctly answering every question, you have won: " + str(List_of_money[qnr+1-joker_check(joker, 2)]) + "€") #specific congratulations message if more than 2 jokers were used
    file.writelines([name, "  ",  str(List_of_money[qnr+1-joker_check(joker, 2)]), "\n"])

file.close() #closes file

#"I declare that the work submitted here is from my authorship only. I haven’t used any gen- erative AI to help with any code/text included in my work. I have given credit for the help I had conceptualizing my project. My work respects the university and course code of conduct"
#Aknowledgement:I´d like to thank my dog Bonnie, who inspired question 15 and motivated me. Furthermore, I want to thank my TA Nienke Dekkema for helping me when issues occured.