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
python python-3.x
add a comment |
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
python python-3.x
for one thing you should doif student.upper() == an[i].upper():
instead ofif student == an[i].upper():
– Red Cricket
Nov 19 at 1:09
yourfor
loop will actuallybreak
after every first iteration. not sure why that is there?
– AeroHil
Nov 19 at 2:09
add a comment |
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
python python-3.x
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
python python-3.x
asked Nov 19 at 1:05
searching1
1
1
for one thing you should doif student.upper() == an[i].upper():
instead ofif student == an[i].upper():
– Red Cricket
Nov 19 at 1:09
yourfor
loop will actuallybreak
after every first iteration. not sure why that is there?
– AeroHil
Nov 19 at 2:09
add a comment |
for one thing you should doif student.upper() == an[i].upper():
instead ofif student == an[i].upper():
– Red Cricket
Nov 19 at 1:09
yourfor
loop will actuallybreak
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
add a comment |
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
add a comment |
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))
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 19 at 2:28
xFly.Dragon
342
342
add a comment |
add a comment |
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))
add a comment |
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))
add a comment |
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))
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))
answered Nov 19 at 2:42
JBaltazar
1
1
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
for one thing you should do
if student.upper() == an[i].upper():
instead ofif student == an[i].upper():
– Red Cricket
Nov 19 at 1:09
your
for
loop will actuallybreak
after every first iteration. not sure why that is there?– AeroHil
Nov 19 at 2:09