Loop basics on a game











up vote
0
down vote

favorite












I'm working on this practice task which is a quiz, scenario is if the answers is wrong the to question.. player can attempt to try again but once I have input the correct answer it will run the question again and not the next one. It's repeating the question all over.



Any idea how can I retain the same question if it's wrong and once corrected it will move to the next question and if the player didnt answer it correctly on the given retries it will move onto the next question?



Heres my code:



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("Correctn")
score += 1

else:
print("n Wrong! Try Againn")
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 15n")
input("Press ENTER to exit")


Thanks










share|improve this question






















  • for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
    – Red Cricket
    Nov 19 at 1:09










  • your for loop will actually break after every first iteration. not sure why that is there?
    – AeroHil
    Nov 19 at 2:09















up vote
0
down vote

favorite












I'm working on this practice task which is a quiz, scenario is if the answers is wrong the to question.. player can attempt to try again but once I have input the correct answer it will run the question again and not the next one. It's repeating the question all over.



Any idea how can I retain the same question if it's wrong and once corrected it will move to the next question and if the player didnt answer it correctly on the given retries it will move onto the next question?



Heres my code:



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("Correctn")
score += 1

else:
print("n Wrong! Try Againn")
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 15n")
input("Press ENTER to exit")


Thanks










share|improve this question






















  • for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
    – Red Cricket
    Nov 19 at 1:09










  • your for loop will actually break after every first iteration. not sure why that is there?
    – AeroHil
    Nov 19 at 2:09













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm working on this practice task which is a quiz, scenario is if the answers is wrong the to question.. player can attempt to try again but once I have input the correct answer it will run the question again and not the next one. It's repeating the question all over.



Any idea how can I retain the same question if it's wrong and once corrected it will move to the next question and if the player didnt answer it correctly on the given retries it will move onto the next question?



Heres my code:



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("Correctn")
score += 1

else:
print("n Wrong! Try Againn")
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 15n")
input("Press ENTER to exit")


Thanks










share|improve this question













I'm working on this practice task which is a quiz, scenario is if the answers is wrong the to question.. player can attempt to try again but once I have input the correct answer it will run the question again and not the next one. It's repeating the question all over.



Any idea how can I retain the same question if it's wrong and once corrected it will move to the next question and if the player didnt answer it correctly on the given retries it will move onto the next question?



Heres my code:



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("Correctn")
score += 1

else:
print("n Wrong! Try Againn")
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 15n")
input("Press ENTER to exit")


Thanks







python python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 1:05









searching1

1




1












  • for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
    – Red Cricket
    Nov 19 at 1:09










  • your for loop will actually break after every first iteration. not sure why that is there?
    – AeroHil
    Nov 19 at 2:09


















  • for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
    – Red Cricket
    Nov 19 at 1:09










  • your for loop will actually break after every first iteration. not sure why that is there?
    – AeroHil
    Nov 19 at 2:09
















for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
– Red Cricket
Nov 19 at 1:09




for one thing you should do if student.upper() == an[i].upper(): instead of if student == an[i].upper():
– Red Cricket
Nov 19 at 1:09












your for loop will actually break after every first iteration. not sure why that is there?
– AeroHil
Nov 19 at 2:09




your for loop will actually break after every first iteration. not sure why that is there?
– AeroHil
Nov 19 at 2:09












2 Answers
2






active

oldest

votes

















up vote
0
down vote













reverse the for loop & while loop



looks like you're handling retry count with "while count < 3"



and questions with "for i in range (0,3)"



#if you want to go through all questions, try len(qs)
for i in range (0,3):
#reset your retry count?
count = 0
while count < 3:

student = input(qs[i]+ "n Ilagay ang iyong sagot: ").upper()
## while count < 3:

if student == an[i].upper():
print("Correctn")
score += 1
break #<-instead, break here
else:
print("n Wrong! Try Againn")
print("Attempt",count)
count += 1

#break <-no need to break here





share|improve this answer




























    up vote
    0
    down vote













    Can you play with the loops and conditions!
    Try this:



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

    i, score = 0, 0
    main_bucle = True

    while main_bucle:

    count = 0

    if i == 15:
    break
    else:
    i+=1

    print(qs[i-1]+ "nIlagay ang iyong sagot: ")

    while count < 3:

    print("Attempt: " + str(count+1))

    answ = input().upper()

    if answ == an[i-1].upper():
    print("nCorrect!n")
    score += 1
    break

    else:
    print("nWrong! Try Againn")
    count+=1

    print("You score is: " + str(score))





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367083%2floop-basics-on-a-game%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      reverse the for loop & while loop



      looks like you're handling retry count with "while count < 3"



      and questions with "for i in range (0,3)"



      #if you want to go through all questions, try len(qs)
      for i in range (0,3):
      #reset your retry count?
      count = 0
      while count < 3:

      student = input(qs[i]+ "n Ilagay ang iyong sagot: ").upper()
      ## while count < 3:

      if student == an[i].upper():
      print("Correctn")
      score += 1
      break #<-instead, break here
      else:
      print("n Wrong! Try Againn")
      print("Attempt",count)
      count += 1

      #break <-no need to break here





      share|improve this answer

























        up vote
        0
        down vote













        reverse the for loop & while loop



        looks like you're handling retry count with "while count < 3"



        and questions with "for i in range (0,3)"



        #if you want to go through all questions, try len(qs)
        for i in range (0,3):
        #reset your retry count?
        count = 0
        while count < 3:

        student = input(qs[i]+ "n Ilagay ang iyong sagot: ").upper()
        ## while count < 3:

        if student == an[i].upper():
        print("Correctn")
        score += 1
        break #<-instead, break here
        else:
        print("n Wrong! Try Againn")
        print("Attempt",count)
        count += 1

        #break <-no need to break here





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          reverse the for loop & while loop



          looks like you're handling retry count with "while count < 3"



          and questions with "for i in range (0,3)"



          #if you want to go through all questions, try len(qs)
          for i in range (0,3):
          #reset your retry count?
          count = 0
          while count < 3:

          student = input(qs[i]+ "n Ilagay ang iyong sagot: ").upper()
          ## while count < 3:

          if student == an[i].upper():
          print("Correctn")
          score += 1
          break #<-instead, break here
          else:
          print("n Wrong! Try Againn")
          print("Attempt",count)
          count += 1

          #break <-no need to break here





          share|improve this answer












          reverse the for loop & while loop



          looks like you're handling retry count with "while count < 3"



          and questions with "for i in range (0,3)"



          #if you want to go through all questions, try len(qs)
          for i in range (0,3):
          #reset your retry count?
          count = 0
          while count < 3:

          student = input(qs[i]+ "n Ilagay ang iyong sagot: ").upper()
          ## while count < 3:

          if student == an[i].upper():
          print("Correctn")
          score += 1
          break #<-instead, break here
          else:
          print("n Wrong! Try Againn")
          print("Attempt",count)
          count += 1

          #break <-no need to break here






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 2:28









          xFly.Dragon

          342




          342
























              up vote
              0
              down vote













              Can you play with the loops and conditions!
              Try this:



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

              i, score = 0, 0
              main_bucle = True

              while main_bucle:

              count = 0

              if i == 15:
              break
              else:
              i+=1

              print(qs[i-1]+ "nIlagay ang iyong sagot: ")

              while count < 3:

              print("Attempt: " + str(count+1))

              answ = input().upper()

              if answ == an[i-1].upper():
              print("nCorrect!n")
              score += 1
              break

              else:
              print("nWrong! Try Againn")
              count+=1

              print("You score is: " + str(score))





              share|improve this answer

























                up vote
                0
                down vote













                Can you play with the loops and conditions!
                Try this:



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

                i, score = 0, 0
                main_bucle = True

                while main_bucle:

                count = 0

                if i == 15:
                break
                else:
                i+=1

                print(qs[i-1]+ "nIlagay ang iyong sagot: ")

                while count < 3:

                print("Attempt: " + str(count+1))

                answ = input().upper()

                if answ == an[i-1].upper():
                print("nCorrect!n")
                score += 1
                break

                else:
                print("nWrong! Try Againn")
                count+=1

                print("You score is: " + str(score))





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Can you play with the loops and conditions!
                  Try this:



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

                  i, score = 0, 0
                  main_bucle = True

                  while main_bucle:

                  count = 0

                  if i == 15:
                  break
                  else:
                  i+=1

                  print(qs[i-1]+ "nIlagay ang iyong sagot: ")

                  while count < 3:

                  print("Attempt: " + str(count+1))

                  answ = input().upper()

                  if answ == an[i-1].upper():
                  print("nCorrect!n")
                  score += 1
                  break

                  else:
                  print("nWrong! Try Againn")
                  count+=1

                  print("You score is: " + str(score))





                  share|improve this answer












                  Can you play with the loops and conditions!
                  Try this:



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

                  i, score = 0, 0
                  main_bucle = True

                  while main_bucle:

                  count = 0

                  if i == 15:
                  break
                  else:
                  i+=1

                  print(qs[i-1]+ "nIlagay ang iyong sagot: ")

                  while count < 3:

                  print("Attempt: " + str(count+1))

                  answ = input().upper()

                  if answ == an[i-1].upper():
                  print("nCorrect!n")
                  score += 1
                  break

                  else:
                  print("nWrong! Try Againn")
                  count+=1

                  print("You score is: " + str(score))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 2:42









                  JBaltazar

                  1




                  1






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367083%2floop-basics-on-a-game%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin