Python Forum
Error in coding project, any help?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in coding project, any help?
#1
Hello! I've been doing some coding exercises from the book "Coding Projects in Python" and I came into an error during one of the projects. The coding is exact to the book and this isn't the first time the book's had errors. Can someone help me with the code? Wall
The code is a simple quiz, and it's supposed to give you three chances for each question. It tallies points based on how many times you try to guess. If you get the answer correct the first time each time you get full points. When you get the answer wrong it docks a point and says "sorry wrong answer try again. But when I run it and enter the correct answer to the question, it says "Correct answer! Sorry, wrong answer!" and only gives you a single chance for one question. I suspect that it might have something to do with the fact that it says "if attempt <2" then it spits out "sorry wrong answer try again." Because ALL first attempts would be <2!!?? All help is appreciated! LOL

def check_guess(guess, answer):
global score
still_guessing = True
attempt = 0
while still_guessing and attempt < 3:
if guess.lower() == answer.lower():
print('Correct Answer!')
score = score + 3 - attempt
still_guessing = False
else:
if attempt < 2:
guess = input('Sorry, wrong answer! Try again.')
attempt = attempt + 1

if attempt == 3:
print('The correct answer is ' + answer)
score = 0
print('Guess the Animal!')
guess1 = input('Which bear lives at the North pole?')
check_guess(guess1, 'polar bear')
guess2 = input('Which is the fastest land animal?')
check_guess(guess2, 'cheetah')
guess3 = input('Which is the largest animal?')
check_guess(guess3, 'blue whale')
guess4 = input('What is the smallest bird?')
check_guess(guess4, 'bee hummingbird')
guess5 = input('Which is the most adorable sea creature?')
check_guess(guess5, 'adorabilis')

print('Your score is ' + str(score))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with coding project jjvoc 4 496 Feb-14-2024, 01:14 PM
Last Post: jjvoc
  Coding error. xflyerwdavis 2 535 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding error. Can't open directory EddieG 6 1,139 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Coding Error EddieG 2 551 Jul-09-2023, 02:59 AM
Last Post: EddieG
  project coding python marcel2807 2 50,290 Dec-18-2020, 08:37 PM
Last Post: LastStopDEVS
  python coding error isntitzee 1 2,218 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,743 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 2,103 Sep-27-2020, 04:17 PM
Last Post: deanhystad
  Adafruit LIS3DH coding error FitDad73 1 2,012 Aug-30-2020, 01:37 AM
Last Post: bowlofred
  Coding error- help FatherYeals 3 33,481 Mar-27-2020, 02:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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