Python Forum
Basic Quiz/Game - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Basic Quiz/Game (/thread-14161.html)

Pages: 1 2


Basic Quiz/Game - searching1 - Nov-17-2018

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")



RE: Basic Quiz/Game - j.crater - Nov-17-2018

Hello, the "break" on line #39 should probably be indented. Now the break is always encountered on first for loop iteration.


RE: Basic Quiz/Game - woooee - Nov-17-2018

    while count < 3: 
        for i in range (0,3):
Both of these statements do the same thing. They both access the first 3 questions.


RE: Basic Quiz/Game - searching1 - Nov-17-2018

(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?


RE: Basic Quiz/Game - ichabod801 - Nov-17-2018

(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



RE: Basic Quiz/Game - searching1 - Nov-18-2018

(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.


RE: Basic Quiz/Game - ichabod801 - Nov-18-2018

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.


RE: Basic Quiz/Game - searching1 - Nov-18-2018

(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.


RE: Basic Quiz/Game - ichabod801 - Nov-18-2018

Then get rid of the while count loop, it's not doing anything.


RE: Basic Quiz/Game - searching1 - Nov-18-2018

(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