Trying to make a Python Trivia Game/Help w/pseudocode

This is the place for queries that don't fit in any of the other categories.

Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Thu Oct 10, 2013 6:12 pm

I want to try and struggle through the coding myself but would like help with the pseudocode.

Trivia Game
Use python lists to store 10 trivia questions and answers of your choice.
Out of the 10 questions, ask the user 4 randomly selected questions each round.
Make sure a question is not repeated during the run of the program.
When the user answers the question, check if the answer is correct or not. Display a message indicating correct or incorrect.
Record the score: 1 point for each correct answer.
At the end of the 4 questions:
Display the score.
Ask the user if they would like to play another round (another 4 questions)
If the user wants to play another round, keep the same score. Do not repeat questions between rounds.
If the user says no, then exit the game
Continuously check if all of the questions have been asked, if so then display an apology message and exit.
Last edited by micseydel on Thu Oct 10, 2013 9:59 pm, edited 1 time in total.
Reason: Locked OP.
skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby Crimson King » Thu Oct 10, 2013 7:52 pm

Hello skeers, welcome to the forum. First of all you should read this viewtopic.php?f=10&t=145

Post your attempts to solve this problem, we'll gladly help you after seeing some of your code, expected output and traceback (if any)
Last edited by micseydel on Thu Oct 10, 2013 9:59 pm, edited 1 time in total.
Reason: Removed OP quote after locking OP.
User avatar
Crimson King
 
Posts: 85
Joined: Fri Mar 08, 2013 2:42 pm
Location: Buenos Aires, Argentina

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Thu Oct 10, 2013 9:04 pm

thx, for the response and that is kinda what i am struggling with getting started if i could get help with just pseudo code it would be a big help.
skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby micseydel » Thu Oct 10, 2013 10:04 pm

Hello skeers, we're happy to help with specific problems you're having but you can't just post your homework and expect us to do it for you (not even pseudo-code). We're here when you don't know what the next step is, but you should be able to know the next step here.

Take for example
skeers wrote:Use python lists to store 10 trivia questions and answers of your choice.


Have you done this? If not, what's the problem? If so, the next thing is to select randomly from that 10; post your attempt, why you think it should work, what it actually does instead of what it is supposed to do. If you really have no idea how to do it, you need to take a step back and figure out what would help you get there (sometimes it's visiting an intro Python tutorial or Googling something).
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1222
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Fri Oct 11, 2013 7:17 am

Ok, thx for response this is what i have so far.

Code: Select all
from random import shuffle

print('Welcome to our Trivia Challenge!')
print('Press enter to start.')
input()

qas = [('How many strikes in baseball till your out?','3'),('How many balls in baseball till you walk?','4'),('How many yards for a first down in football?','10'),('How many downs to reach a first down in football?','4'),('How many minutes till half in soccer?','45'),('How many players on each team on the field in soccer?','11'),('How mnay holes on a typical golf course?','18'),('What Sport is played at Wimbledon?','tennis'),('How many bases on a baseball field?','4'),('How many rounds in a pro boxing match?','10')]

shuffle(qas)
numRight = 0
numWrong = 0
numQuestionsRound = 4

for question, rightAnswer in qas[:numQuestionsRound]:
    answer = input(question + ' ')
    if answer.lower() == rightAnswer:
        print('Correct!')
        print('')
        numRight += 1
    else:
        print('No, the answer is ' + str(rightAnswer))
        print('')
        numWrong += 1
print('You got ' + str(numRight) + ' right and ' + str(numWrong) + ' wrong.')

print('Would you like to play another round?')

print('Thanks for playing!')


I need help with
o If the user wants to play another round, keep the same score. Do not repeat questions between rounds.
o If the user says no, then exit the game
- Continuously check if all of the questions have been asked, if so then display an apology message and exit.
I really can not figure out how to do this any help would be nice.
Last edited by micseydel on Fri Oct 11, 2013 5:38 pm, edited 1 time in total.
Reason: Code tags, lock.
skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby micseydel » Fri Oct 11, 2013 5:46 pm

Thanks for posting your code. Please use code tags next time (as I have above).

skeers wrote:o If the user wants to play another round, keep the same score. Do not repeat questions between rounds.

You can prevent repeating questions by removing them from the list, or some other way of consuming them. I like iterators, but that might be too complex for you.

o If the user says no, then exit the game

You'll need to wrap all the code that needs to be potentially executed more than one time in a loop. The loop's exit condition should be when the user says no.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1222
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Mon Oct 14, 2013 8:25 am

I have figured out how to loop to play again but still do not know how to do the other part. specific help plzzz
skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Mon Oct 14, 2013 8:30 am

Code: Select all
from random import shuffle

print('Welcome to our Trivia Challenge!')
print('Press enter to start.')
input()

qas = [('How many strikes in baseball till your out?','3'),('How many balls in baseball till you walk?','4'),('How many yards for a first down in football?','10'),('How many downs to reach a first down in football?','4'),('How many minutes till half in soccer?','45'),('How many players on each team on the field in soccer?','11'),('How many holes on a typical golf course?','18'),('What Sport is played at Wimbledon?','tennis'),('How many bases on a baseball field?','4'),('How many rounds in a pro boxing match?','10')]

shuffle(qas)
numRight1 = 0
numWrong = 0
numQuestionsRound = 4


for question, rightAnswer in qas[:numQuestionsRound]:
    answer = input(question + ' ')
    if answer.lower() == rightAnswer.lower():
        print('Correct!')
        print('')
        numRight1 += 1
    else:
        print('No, the answer is: ' + str(rightAnswer))
        print('')
        numWrong += 1
print('Your score is ' + str(numRight1))
print('')
print('Do you want to play again? (Yes or No)')
print('')

playagain = 'yes'
response = input()

if response != playagain:
    print('GoodBye!')


while playagain.lower() == response.lower():

   
    shuffle(qas)
    numRight2 = 0
    numWrong = 0
    numQuestionsRound = 4

    for question, rightAnswer in qas[:numQuestionsRound]:
        answer = input(question + ' ')
        if answer.lower() == rightAnswer.lower():
            print('Correct!')
            print('')
            numRight2 += 1
        else:
            print('No, the answer is: ' + str(rightAnswer))
            print('')
            numWrong += 1
    print('Your score is: ' + str(numRight2 + numRight1))
    print('')
    print('Do you want to play again? (Yes or No)')
    print('')
    response = input()

    if playagain.lower() != response.lower():
        print('GoodBye!')
        response = input()

skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby Kebap » Mon Oct 14, 2013 10:05 am

How about ordering like this:

Code: Select all
playagain = 'yes'
response = playagain
while response.lower() == playagain:
  # ... (play game)
  response = input('Do you want to play again? (yes or no)')


The game will be played once, then at the end, the player is asked. Then, maybe, it begins anew.

Advantage: You don't have the same code copied in multiple locations. Better yet would be functions. Do you know how to def?

skeers wrote:I have figured out how to loop to play again but still do not know how to do the other part. specific help plzzz

Code: Select all
from random import shuffle

print('Welcome to our Trivia Challenge!')
print('Press enter to start.')
input()

qas = [('How many strikes in baseball till your out?','3'),('How many balls in baseball till you walk?','4'),('How many yards for a first down in football?','10'),('How many downs to reach a first down in football?','4'),('How many minutes till half in soccer?','45'),('How many players on each team on the field in soccer?','11'),('How many holes on a typical golf course?','18'),('What Sport is played at Wimbledon?','tennis'),('How many bases on a baseball field?','4'),('How many rounds in a pro boxing match?','10')]

shuffle(qas)
numRight1 = 0
numWrong = 0
numQuestionsRound = 4


for question, rightAnswer in qas[:numQuestionsRound]:
    answer = input(question + ' ')
    if answer.lower() == rightAnswer.lower():
        print('Correct!')
        print('')
        numRight1 += 1
    else:
        print('No, the answer is: ' + str(rightAnswer))
        print('')
        numWrong += 1
print('Your score is ' + str(numRight1))
print('')
print('Do you want to play again? (Yes or No)')
print('')

playagain = 'yes'
response = input()

if response != playagain:
    print('GoodBye!')


while playagain.lower() == response.lower():

   
    shuffle(qas)
    numRight2 = 0
    numWrong = 0
    numQuestionsRound = 4

    for question, rightAnswer in qas[:numQuestionsRound]:
        answer = input(question + ' ')
        if answer.lower() == rightAnswer.lower():
            print('Correct!')
            print('')
            numRight2 += 1
        else:
            print('No, the answer is: ' + str(rightAnswer))
            print('')
            numWrong += 1
    print('Your score is: ' + str(numRight2 + numRight1))
    print('')
    print('Do you want to play again? (Yes or No)')
    print('')
    response = input()

    if playagain.lower() != response.lower():
        print('GoodBye!')
        response = input()

Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 387
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Trying to make a Python Trivia Game/Help w/pseudocode

Postby skeers » Mon Oct 14, 2013 3:07 pm

Code: Select all
from random import shuffle

print('Welcome to our Trivia Challenge!')
print('Press enter to start.')
input()

def playgame():
   
    qas = [('How many strikes in baseball till your out?','3'),('How many balls in baseball till you walk?','4'),('How many yards for a first down in football?','10'),('How many downs to reach a first down in football?','4'),('How many minutes till half in soccer?','45'),('How many players on each team on the field in soccer?','11'),('How many holes on a typical golf course?','18'),('What Sport is played at Wimbledon?','tennis'),('How many bases on a baseball field?','4'),('How many rounds in a pro boxing match?','10')]

    shuffle(qas)
    numRight1 = 0
    numWrong = 0
    numQuestionsRound = 4


    for question, rightAnswer in qas[:numQuestionsRound]:
        answer = input(question + ' ')
        if answer.lower() == rightAnswer.lower():
            print('Correct!')
            print('')
            numRight1 += 1
        else:
            print('No, the answer is: ' + str(rightAnswer))
            print('')
            numWrong += 1

def score():
   

        print('Your score is ' + str(numRight1))
        print('')
   

playagain = 'yes'
response = playagain

while response.lower() == playagain:
    playgame()
    score()
    response = input('Do you want to play again? Yes or No')

   



How should i define score so i keeps track through rounds and still help with not repeating questions through rounds and if all questions have been asked print message and exit
skeers
 
Posts: 6
Joined: Thu Oct 10, 2013 6:04 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 2 guests