Answer to Question #159867 in Python for Meera

Question #159867

#(a) Write a program that asks the user the same single, simple, random math problem until they get it right. (1A, 1C)

#(b) Add the option for the user to specify how many problems they want to answer. (1A)

#(c) Don't do a fixed number of questions. Instead, ask the user at the end of each question sequence (i.e., when they finally get it right) if they want to continue. (1C)

#(d) Keep track of the user's attempts and the total number of questions, and then report their score (i.e., "you took X tries to answer Y questions correctly") (1A)

#(e) Set a maximum number of tries for each question. When the user makes their last guess, tell them the answer and move on. (1A)


1
Expert's answer
2021-02-01T08:01:40-0500
data = """Round 1: Geography - Questions
1) What is the capital of Chile?
2) What is the highest mountain in Britain?
3) What is the smallest country in the world?
4) Alberta is a province of which country?
5) How many countries still have the shilling as currency?
6) Which is the only vowel not used as the first letter in a US State?
7) What is the largest country in the world?
8) Where would you find the River Thames?
9) What is the hottest continent on Earth?
10) What is the longest river in the world?
Round 1: Geography - Answers
1) Santiago
2) Ben Nevis
3) Vatican City
4) Canada
5) Four – Kenya, Uganda, Tanzania and Somalia
6) E
7) Russia
8) London, UK
9) Africa
10) River Nile
Round 2: History - Questions
1) What did the Romans call Scotland?
2) Who was made Lord Mayor of London In 1397, 1398, 1406 And 1419?
3) Who was Henry VIIIs last wife?
4) Who was the youngest British Prime Minister?
5) In which year was Joan of Arc burned at the stake?
6) Which nationality was the polar explorer Roald Amundsen?
7) Who was the first female Prime Minister of Australia?
8) Which English explorer was executed in 1618, fifteen year after being found guilty of conspiracy against King James I of England and VI of Scotland?
9) Which English city was once known as Duroliponte?
10) The first successful vaccine was introduced by Edward Jenner in 1796. Which disease did it guard against?
Round 2: History - Answers
1) Caledonia
2) Richard (Dick) Whittington
3) Catherine Parr
4) William Pitt (The Younger)
5) 1431
6) Norwegian
7) Julia Gillard (2010-2013)
8) Sir Walter Raleigh
9) Cambridge
10) Smallpox
Round 3: Sport - Questions
1) What are the five colours of the Olympic rings?
2) In football, which team has won the Champions League (formerly the European Cup) the most?
3) How many players are there in a rugby league team?
4) Which horse is the only three-time winner of the Grand National?
5) Since 1977, where has snooker's World Championship taken place?
6) In tennis, what piece of fruit is found at the top of the men's Wimbledon trophy?
7) Who won the FIFA Women's World Cup in 2019?
8) In bowling, what is the term given for three consecutive strikes?
9) How many world titles has Phil Talyor won in darts?
10) In golf, where does the Masters take place?
Round 3: Sport - Answers
1) Blue, yellow, black, green and red
2) Real Madrid (13)
3) 13
4) Red Rum
5) Crucible Theatre
6) Pineapple
7) USA
8) A turkey
9) 16
10) Augusta National
Round 4: Politics - Questions
1) Who was the only British Prime Minister to be assassinated?
2) How long does Prime Minister’s Questions last?
3) How many Members of Parliament (MPs) are there?
4) What is the middle name of Angela Merkel?
5) America's Republican Party is commonly referred to as the GOP - what does the GOP stand for?
6) Who is Donald Trump's vice president?
7) In which year did Britain originally join the EEC, now known as the European Union?
8) How many of the six founding members of the European Union can you name? A point for each.
9) What is the name given to the group of people who make sure MPs attend important votes?
10) On what subject was the first referendum in Britain?
Round 4: Politics - Answers
1) Spencer Perceval - May 1812
2) 30 minutes
3) 650
4) Dorothea
5) Grand Old Party
6) Mike Pence
7) 1973
8) Belgium, France, West Germany, Italy, Luxembourg, Netherlands
9) Whips
10) Remaining in the EEC (1975)
Round 5: Food and drink - Questions
1) Which nuts are used in marzipan?
2) What is the most famous Mexican beer?
3) Which country is the origin of the cocktail Mojito?
4) What is Japanese sake made from?
5) Which vitamin is the only one that you will not find in an egg?
6) What is the chemical formula for Table Salt?
7) What does IPA stand for?
8) Which meat is used in Glamorgan sausages?
9) What ingredient is included in food in a Florentine style?
10) Which fish is the main ingredient of Scotch Woodcock?
Round 5: Food and drink - Answers
1) Almonds
2) Corona
3) Cuba
4) Rice
5) Vitamin C
6) NaC1
7) Indian Pale Ale
8) None, they are made from cheese
9) Spinach
10) Anchovy
Round 6: TV - Questions
1) What is the capital of Westeros in Game of Thrones?
2) Who presented TV quiz Blockbusters between 1983 and 1995?
3) In Netflix's Tiger King, what is the name of Carole Baskin's second husband who many believe she fed to the tigers?
4) In Emmerdale, on New Year's Day in 2004, who died when The Woolpack pub's chimney came crashing down in a storm?
5) In what Netflix series does actress Gillian Anderson play a sex therapist?
6) Who played Queen Elizabeth II in the first two seasons of The Crown?
7) BBC Three series Normal People is based on a book but who is the author?
8) The six main stars of Friends appeared in all 236 episodes. Who is the next most regular character to appear in the show?
9) Who does the voiceover on Love Island?
10) In what year was the first episode of Coronation Street broadcasted on ITV?
Round 6: TV - Answers
1) King’s Landing
2) Bob Holness
3) Don Lewis
4) Trisha Dingle
5) Sex Education
6) Claire Foy
7) Sally Rooney
8) Gunther (151 episodes)
9) Iain Stirling
10) 1960
Round 7: Music - Questions
1) One Direction is known for being the runners-up in The X Factor in 2010, but who came first?
2) Which singer has the most UK Number One singles ever?
3) What was Britney Spears’ first single called?
4) Who is the only singer to have ever performed more than one James Bond theme song?
5) Who were the three headliners of Glastonbury 2019?
6) Who is the only musician ever to have been awarded the Nobel prize for literature?
7) Which Beatles song was banned from the BBC for its lyrics?
8) Who was the first female artist to achieve a UK number one with a self-written song?
9) What is the real name of U2’s guitarist, known as The Edge?
10) What is David Bowie’s real name?
Round 7: Music - Answers
1) Matt Cardle
2) Elvis Presley
3) Baby One More Time
4) Shirley Bassey (John Barry and his orchestra does not count as their theme is reused.)
5) The Cure, The Killers and Stormzy
6) Bob Dylan
7) I am the Walrus
8) Kate Bush
9) David Evans
10) David Jones
Round 8: Football - Questions
1) Which year was the Premier League founded?
2) Real Madrid won the first five European Cups - but which club was the second to win Europe's elite competition?
3) Who holds the record for most consecutive Premier League appearances (310)?
4) Which club won the 2017 UEFA Super Cup?
5) Who was manager of Manchester City when they won their first Premier League title?
6) Who has scored more career goals - Cristiano Ronaldo or Lionel Messi?
7) Which Dutch player was voted 'European Player of the Century' in 1999?
8) Who scored the first Premier League hat-trick?
9) Which English referee officiated the 2010 World Cup final?
10) Wayne Rooney scored his Premier League first goal against which team?
Round 8: Football - Answers
1) 1992
2) Benfica
3) Brad Friedel
4) Real Madrid
5) Roberto Mancini
6) Cristiano Ronaldo
7) Johan Cruyff
8) Eric Cantona
9) Howard Webb
10) Arsenal"""


def form_q_a(s):
    ss = s.split('\n')
    questions = []
    answers = []
    for i in range(8):
        for j in range(1,11):
            questions.append(ss[j].split(' ',1)[1])
            answers.append(ss[11+j].split(' ',1)[1])
    return questions, answers


questions, answers = form_q_a(data)
length = len(questions)

while True:
    n = int(input("Enter number of questions you want to answer [1-{0}]: ".format(len(questions))))
    if (0 < n <= length):
        break

m = 1
score = 0

from random import randint as rnd


while m <= n:
    print("\n\nQuestion {0} / {1}\n".format(m,n))
    i = rnd(1,length)
    for _ in range(rnd(2,5)):
        if answers[i] == input("{0} ".format(questions[i])):
            print("Right\n")
            score += 1
            break
        else:
            print("Wrong answer.\n")
    else:
        print("Right answer : {0}\n".format(answers[i]))
    m += 1
    
    ans = input("Next question - 'y',   Exit - 'n': ")
    while ans not in {'y','n'}:
        ans = input("Enter 'y' for next question or 'n' for exit: ")
    if ans == 'n':
        break
else:
    print("\nSorry, it was the last quesiton.")


print("\n\nYour score = {0} / {1}".format(score, n))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS