Knowee
Questions
Features
Study Tools

Objective:To work with listsScenario:A doctor's survey results information is stored in 2 lists. The first list represents all doctors' IDs (working and non-working). The second list represents only the working doctors' IDs. Please find the doctor ids who are not working.  Write a program in Python to perform the above task.Input and Output Format:The first line of input corresponds to n1, the size of the first list, and the next n1 lines correspond to the elements of the first list.The next line corresponds to n2, the size of the second list, and the next n2 lines correspond to the elements of the second listOutput is the id's of doctors who is not workingNote:1. Print "Invalid list size",  if the size of the list entered is a negative number  or zero and terminate the program2. Print "Invalid Id", if the id entered is any negative number or zero, and terminate the program.Sample Input 1:772345613345Sample Output 1:Not Working Doctors' IDs are:7 2 6 1 Sample Input 2:7723456-1Sample Output 2:Invalid Id Sample Input 3:5452-5Sample Output 3:Invalid IdSample Input 4:0Sample Output 4:Invalid list size Sample Input 5:3674433-5Sample Output 5:Invalid list sizeSample Input 6:315367820Sample Output 6:Invalid Id

Question

Objective:To work with listsScenario:A doctor's survey results information is stored in 2 lists. The first list represents all doctors' IDs (working and non-working). The second list represents only the working doctors' IDs. Please find the doctor ids who are not working.  Write a program in Python to perform the above task.Input and Output Format:The first line of input corresponds to n1, the size of the first list, and the next n1 lines correspond to the elements of the first list.The next line corresponds to n2, the size of the second list, and the next n2 lines correspond to the elements of the second listOutput is the id's of doctors who is not workingNote:1. Print "Invalid list size",  if the size of the list entered is a negative number  or zero and terminate the program2. Print "Invalid Id", if the id entered is any negative number or zero, and terminate the program.Sample Input 1:772345613345Sample Output 1:Not Working Doctors' IDs are:7 2 6 1 Sample Input 2:7723456-1Sample Output 2:Invalid Id Sample Input 3:5452-5Sample Output 3:Invalid IdSample Input 4:0Sample Output 4:Invalid list size Sample Input 5:3674433-5Sample Output 5:Invalid list sizeSample Input 6:315367820Sample Output 6:Invalid Id

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The problem is asking to write a Python program that will find the IDs of doctors who are not working. The IDs of all doctors and the IDs of working doctors are given in two separate lists. The program should print the IDs of doctors who are not working.

Here is a step-by-step solution:

  1. First, we need to get the input from the user. The first input is the size of the first list (n1), which represents all doctors' IDs. If n1 is less than or equal to 0, print "Invalid list size" and terminate the program.

  2. Next, we need to get the elements of the first list. If any element is less than or equal to 0, print "Invalid Id" and terminate the program.

  3. Then, we need to get the size of the second list (n2), which represents the working doctors' IDs. If n2 is less than or equal to 0, print "Invalid list size" and terminate the program.

  4. Next, we need to get the elements of the second list. If any element is less than or equal to 0, print "Invalid Id" and terminate the program.

  5. Now, we need to find the IDs of doctors who are not working. We can do this by finding the difference between the first list and the second list. In Python, we can use the set difference operation to do this.

  6. Finally, print the IDs of doctors who are not working.

Here is the Python code that implements the above steps:

n1 = int(input())
if n1 <= 0:
    print("Invalid list size")
    exit()

all_ids = []
for _ in range(n1):
    id = int(input())
    if id <= 0:
        print("Invalid Id")
        exit()
    all_ids.append(id)

n2 = int(input())
if n2 <= 0:
    print("Invalid list size")
    exit()

working_ids = []
for _ in range(n2):
    id = int(input())
    if id <= 0:
        print("Invalid Id")
        exit()
    working_ids.append(id)

not_working_ids = set(all_ids) - set(working_ids)
print("Not Working Doctors' IDs are:", ' '.join(map(str, not_working_ids)))

This program first reads the sizes and elements of the two lists, checks for invalid inputs, finds the difference between the two lists, and prints the result.

This problem has been solved

Similar Questions

Input and Output Format:The first line of input corresponds to n1, the size of the first list, and the next n1 lines correspond to the elements of the first list.The next line corresponds to n2, the size of the second list, and the next n2 lines correspond to the elements of the second listOutput is the id's of doctors who is not workingNote:1. Print "Invalid list size",  if the size of the list entered is a negative number  or zero and terminate the program2. Print "Invalid Id", if the id entered is any negative number or zero, and terminate the program.Sample Input 1:772345613345Sample Output 1:Not Working Doctors' IDs are:7 2 6 1

Write a Python program to convert a list to a tuple

You are given two lists of different lengths of positive integers. Write an algorithm to count the number of elements that are not common to each list.InputThe first line of the input consists of an integer - listInput1_size, an integer representing the number of elements in the first list (N).The second line consists of N space-separated integers representing the first list of positive integers.The third line consists of an integer- listInput2_size, representing the number of elements in the second list (M).The last line consists of M space-separated integers representing the second list of positive integers.OutputPrint a positive integer representing the count of elements that are not common to both the lists of integers.ExampleInput:111 1 2 3 4 5 5 7 6 9 101011 12 13 4 5 6 7 18 19 20Output:12Explanation:The numbers that are not common to both lists are [1, 1, 2, 3, 9, 10, 11, 12, 13, 18, 19, 20].So, the output is 12.

You are given two lists of different lengths of positive integers. Write an algorithm to count the number of elements that are not common to each list.InputThe first line of the input consists of an integer - listInput1_size, an integer representing the number of elements in the first list (N).The second line consists of N space-separated integers representing the first list of positive integers.The third line consists of an integer- listInput2_size, representing the number of elements in the second list (M).The last line consists of M space-separated integers representing the second list of positive integers.

Analyse the following code and predict the output.list1 = [2,4,6,8,10,12,14,16,18,20]print (list1[0:1],list1[5:7])Select one:Error[2] [12, 14][4][14,16][2][12,14,16]

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.