Python Forum
Program: Foot Bones Quiz
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program: Foot Bones Quiz
#1
Quote:Program: Foot Bones Quiz
Create a function that will iterate through foot_bones looking for a match of a string argument
Call the function 2 times with the name of a footbone
print immediate feedback for each answer (correct - incorrect)
print the total # of foot_bones identified
The program will use the foot_bones list:

foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]

Bonus: remove correct response item from list if correct so user cannot answer same item twice


Ciao,
I can't uderstand why the code below don't print the identified value correctly.
As far as I understand "identified = 0" inizialize the variable and when the correct bone is inserted "identified += 1" should count +1 ... but the last line "print(identified)" result always 0
thanks


# [ ] Complete Foot Bones Quiz
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
             "intermediate cuneiform", "medial cuneiform"]

def quiz():
    identified = 0
    for i in range(2):
        footbone = input("osso del piede: ")
        if footbone in foot_bones:
            print('correct')
            identified += 1
            foot_bones.remove(footbone)
        else:
            print("not found")
        

quiz()
print(foot_bones)
print(identified)
Reply
#2
It fails on line 19 because you don't have a variable named identified in scope.
the identified inside quiz goes out of scope as soon as you leave the function.

you should return identified;
# [ ] Complete Foot Bones Quiz
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
             "intermediate cuneiform", "medial cuneiform"]

def quiz():
    identified = 0
    for i in range(2):
        footbone = input("osso del piede: ")
        if footbone in foot_bones:
            print('correct')
            identified += 1
            foot_bones.remove(footbone)
        else:
            print("not found")
    return identified
 
identified = quiz()
print(foot_bones)
print('You have identified {} correctly'.format(identified))
Results:
Output:
osso del piede: talus correct osso del piede: navicular correct ['calcaneus', 'cuboid', 'lateral cuneiform', 'intermediate cuneiform', 'medial cuneiform'] You have identified 2 correctly
Reply
#3
Larz60+,
thank you very much Smile
There are still things I have to understan better Confused

p.s.
nice trick the:
{}.format(identified)
I did not still encouterded in the course
Reply


Forum Jump:

User Panel Messages

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