Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Quiz/Game
#1
Hi, I'm working on this practice task which is like a quiz, When if the after is correct the question repeats all the time and not moving to the next question on the list?? Any inputs? Thanks

print("USE FUNCTION --> game()")
def main():
    pass


qs = ["Grass", "Horn", "Feather", "Laugh", "Smooth", "Mountain", "Abundance", "absorb", "cheapskate", "citizenship", "classify", "kingdom", "kilometer", "poet", "free"]
an = ["damo", "sungay", "balihibo", "tawa", "makinis", "bundok", "kasaganahan", "sipsipin", "barat", "pagkamamamayan", "suriin", "kaharian", "kilometro", "makata", "malaya"]


##def attempt():
##    count = 0
##    att = input("Ilagay ang iyong sagot: ")     
##    
##        print("Mali ang iyong sagot, Subukan Muli")
##        break
    
def game():
    print("---------------------------------")
    print("Welcome to game DAY 2 Quiz - Translate English to Tagalog")
    print("---------------------------------\n")

    score = 0
    count = 0

#Select I then use range staring from 0 till the end minus
    while count < 3: 
        for i in range (0,3):
            student = input(qs[i]+ "\n Ilagay ang iyong sagot: ").upper()
    ##        while count < 3:
                                
            if student == an[i].upper():
                print("Correct\n")
                score += 1
              
            else:
                print("\n Wrong! Try Again\n")
                print("Attempt",count)
                count += 1
            break
              
    print("Ang tamang sagot ay",an[i])
    name = input("What is you name: ").upper()            
    print("Hey!",name,"Your final score is",score,"out of 15\n")
    input("Press ENTER to exit")
Reply
#2
Hello, the "break" on line #39 should probably be indented. Now the break is always encountered on first for loop iteration.
Reply
#3
    while count < 3: 
        for i in range (0,3):
Both of these statements do the same thing. They both access the first 3 questions.
Reply
#4
(Nov-17-2018, 09:43 AM)j.crater Wrote: Hello, the "break" on line #39 should probably be indented. Now the break is always encountered on first for loop iteration.

else:
                print("\n Wrong! Try Again\n")
                print("Attempt",count)
                count += 1
                break
Tried putting inside the else and It always repeat to the 1 question when false. Thanks

(Nov-17-2018, 05:35 PM)woooee Wrote:
    while count < 3: 
        for i in range (0,3):
Both of these statements do the same thing. They both access the first 3 questions.

Any idea how can I retain the same question if it's wrong?
Reply
#5
(Nov-17-2018, 06:10 PM)searching1 Wrote: Any idea how can I retain the same question if it's wrong?

To continue asking if the answer is wrong, use a while loop, and exit if the answer is correct. Something like:

        while True:
            student = input(qs[i]+ "\n Ilagay ang iyong sagot: ").upper()
                                 
            if student == an[i].upper():
                print("Correct\n")
                score += 1
                break
               
            else:
                print("\n Wrong! Try Again\n")
                print("Attempt",count)
                count += 1
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
(Nov-17-2018, 06:36 PM)ichabod801 Wrote:
(Nov-17-2018, 06:10 PM)searching1 Wrote: Any idea how can I retain the same question if it's wrong?

To continue asking if the answer is wrong, use a while loop, and exit if the answer is correct. Something like:

        while True:
            student = input(qs[i]+ "\n Ilagay ang iyong sagot: ").upper()
                                 
            if student == an[i].upper():
                print("Correct\n")
                score += 1
                break
               
            else:
                print("\n Wrong! Try Again\n")
                print("Attempt",count)
                count += 1

Result is the same, It;s keeps repeating the question once break has been initiated.
Reply
#7
Well, where did you put it in the code? And did you fix the issue with the two loops you already have? For example, if you just put that within the for loop, and answer them correctly, it will keep asking the first three questions in order forever, because count is never updated, so the while count loop keeps repeating the for i loop.

I mean what is count supposed to do? Do you want the game to end after three wrong answers? If so, you need to remove the while count loop, and add an if count >= 3: break to the for i loop.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
(Nov-18-2018, 02:37 AM)ichabod801 Wrote: Well, where did you put it in the code? And did you fix the issue with the two loops you already have? For example, if you just put that within the for loop, and answer them correctly, it will keep asking the first three questions in order forever, because count is never updated, so the while count loop keeps repeating the for i loop. I mean what is count supposed to do? Do you want the game to end after three wrong answers? If so, you need to remove the while count loop, and add an if count >= 3: break to the for i loop.
Hi, Put the code inside the while statement... But question still repeart.
Count is the attempt value for player, in this case if it falls to the wrong question.. program should give the player anoter attempt to answer the same question.
Reply
#9
Then get rid of the while count loop, it's not doing anything.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#10
(Nov-18-2018, 03:10 AM)ichabod801 Wrote: Then get rid of the while count loop, it's not doing anything.
Hi ichabod801, Thanks for your response....

Removed the while count and the for loop and I'm having issue with the input and I cannot run the program.

while True:
      student = input(qs[0,14]+ "\n Ilagay ang iyong sagot: ").upper()
                                  
      if student == an[0,14].upper():
          print("Correct\n")
          score += 1
          break
                  
      else:
          print("\n Wrong! Try Again\n")
          print("Attempt",count)
          count += 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  quiz game - problem with loading statements from file lapiduch 2 1,028 Apr-20-2023, 06:13 PM
Last Post: deanhystad
  Code: Creating a basic python game? searching1 5 3,375 Nov-12-2018, 05:18 AM
Last Post: searching1
  help setting questions and answers in quiz game? yoyoitsjess 3 3,615 May-10-2018, 07:35 AM
Last Post: buran
  Quiz Game Help (ASAP Please!) beginnercoder04 2 3,162 Apr-15-2018, 04:13 AM
Last Post: beginnercoder04

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020