Skip to content

Commit e9884b1

Browse files
Merge pull request #308 from Anianonymous/Anianonymous-patch-1.1
Updated quizz.py
2 parents 8608147 + e937c04 commit e9884b1

File tree

1 file changed

+50
-24
lines changed

1 file changed

+50
-24
lines changed

Animal-Quiz-Game/quizz.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1+
import streamlit as st
2+
3+
14
def check_guess(guess, answer):
2-
global score
3-
still_guessing = True
4-
attempt = 0
5-
while still_guessing and attempt < 3:
6-
if guess.lower() == answer.lower():
7-
print("Correct Answer")
8-
score = score + 1
9-
still_guessing = False
10-
else:
11-
if attempt < 2:
12-
guess = input("Sorry Wrong Answer, try again")
13-
attempt = attempt + 1
14-
if attempt == 3:
15-
print("The Correct answer is ",answer )
16-
17-
score = 0
18-
print("Guess the Animal")
19-
guess1 = input("Which bear lives at the North Pole? ")
20-
check_guess(guess1, "polar bear")
21-
guess2 = input("Which is the fastest land animal? ")
22-
check_guess(guess2, "Cheetah")
23-
guess3 = input("Which is the larget animal? ")
24-
check_guess(guess3, "Blue Whale")
25-
print("Your Score is "+ str(score))
5+
if guess and guess.lower() == answer.lower():
6+
return True, "Correct Answer!"
7+
elif guess:
8+
return False, "Sorry, Wrong Answer!"
9+
return None, ""
10+
11+
12+
def main():
13+
st.title("Guess the Animal")
14+
15+
score = 0
16+
17+
st.write("Which bear lives at the North Pole?")
18+
guess1 = st.text_input("Your answer for bear:", key='input1') # Unique key assigned
19+
is_correct1, response1 = check_guess(guess1, "polar bear")
20+
21+
if is_correct1 == True:
22+
score += 1
23+
st.success(response1)
24+
elif is_correct1 == False:
25+
st.error(response1)
26+
27+
st.write("Which is the fastest land animal?")
28+
guess2 = st.text_input("Your answer for land animal:", key='input2') # Unique key assigned
29+
is_correct2, response2 = check_guess(guess2, "cheetah")
30+
31+
if is_correct2 == True:
32+
score += 1
33+
st.success(response2)
34+
elif is_correct2 == False:
35+
st.error(response2)
36+
37+
st.write("Which is the largest animal?")
38+
guess3 = st.text_input("Your answer for largest animal:", key='input3') # Unique key assigned
39+
is_correct3, response3 = check_guess(guess3, "blue whale")
40+
41+
if is_correct3 == True:
42+
score += 1
43+
st.success(response3)
44+
elif is_correct3 == False:
45+
st.error(response3)
46+
47+
st.write("Your Score is:", score)
48+
49+
50+
if __name__ == "__main__":
51+
main()

0 commit comments

Comments
 (0)