Ask Question

Write some code that counts the number of times the value associated with student_id appears in the list associated with incompletes and assigns this value to number_of_incompletes. You may use, if you wish, an additional variable, k.

+5
Answers (1)
  1. 26 April, 06:46
    0
    incompletes = [1,2,1,5,3,4,5,6,5,1,7]

    student_id = 5

    number_of_incompletes = 0

    for k in incompletes:

    if (k = = student_id):

    number_of_incompletes + = 1

    print ("No. of incompletes = ", number_of_incompletes)

    In this program, "incompletes" is a variable where set of values are associated. "student_id" holds the value to be searched in the list. So the counter "number_of_incompletes" is set to 0 and it will be incremented in the for loop if the student id matches. Finally the number of incomplete gets printed.

    Here the student_id is "hard-coded". If you want you get the input from the user too.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write some code that counts the number of times the value associated with student_id appears in the list associated with incompletes and ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers