0
Can someone help me with this code?
Cant seen to print out the total or increase in a for/in loop. the code is in my public codes.
11 Answers
+ 2
#function to search items in a list
def search_item(search_bone):
#counting the total
total_correct = 0
#iterate throught list foot_bones
for bones in foot_bones:
#total does not increase????
if bones.lower() == search.lower():
total_correct += 1
return total_correct
else:
#if not the first item, move on
pass
#no more items
return total_correct
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]
search = "talus"
print(search_item(search))
search = "saga"
print(search_item(search))
+ 2
Omar
I suggest nesting the search_item() function with a while loop and do the total correct count within the while loop.
https://code.sololearn.com/cuz5ezC4aW3n/#py
+ 1
Omar
You got to give us a link to your code.
+ 1
Omar
Your code will not print out the total, because there is nothing in your code asking it to print out the total.
According to your code, it will only take one input, search the array and if the input matches a string in the array it will return a "correct". If no match is found after going through the entire array it will return an "incorrect".
It sounds like you want the function to keep count of how many correct searches you get. Is this correct?
+ 1
yes that is correct . I do put print (total_correct) but i get errors or it just prints "0"
+ 1
Omar
Take a look at the link below-
https://code.sololearn.com/cuz5ezC4aW3n/?ref=app
0
https://code.sololearn.com/csnC026CwNkU/?ref=app
0
that seems to work but if I would get the search from user input.. I would like the program to print immediate feed back for the input.. I had it as once it got the search it would output correct or incorrect
0
true. maybe I'll do a
while foot_bones:
to iterate thought the list and nest an if/else statement to check if its correct. that way it can count but I dont know exactly where in the while loop should the print(total_correct) go.
0
i see. it could take two user inputs. i want it to print the correct but also count it. in your code it double prints correct. where would the total_correct += 1?



