Question

In: Computer Science

def read_list(): """ This function should ask the user for a series of integer values (until...

def read_list():

"""

This function should ask the user for a series of integer values (until the user enters 0 to stop) and store all those values in a list. That list should then be returned by this function.

"""

def remove_duplicates(num_list):

"""

This function is passed a list of integers and returns a new list with all duplicate values from the original list remove.

>>> remove_duplicates([1, 2, 3, 2, 3, 4])

[1, 2, 3, 4]

>>> remove_duplicates([1, 1, 1])

[1]

>>> remove_duplicates([])

[]

"""

def main():

num_list = read_list()

print("Original list entered by user: ")

print(num_list)

no_duplicates = remove_duplicates(num_list)

print("List with duplicates removed: ")

print(no_duplicates)

Solutions

Expert Solution

def read_list():
   num_list=[]   #list to store the inputted integers
   print("Enter a series of integers and 0 to stop: ")
   while True:
       n=int(input())   #taking the input from the user
       if(n==0):   #checking if 0 is entered or not
           break   #if 0 is entered stop asking input
       num_list.append(n)   #if any non zero is entered then add to the list

   return num_list   #return the input list

def remove_duplicates(num_list):
   no_duplicates=[]   #list to store unique values
   for i in num_list:   #looping over all the elements in the list
       if i not in no_duplicates:   #if the element is not found in the no_dupilcates list
           no_duplicates.append(i)   #adding the element to the no_duplicates list

   return no_duplicates    #returning the no_duplicates list

def main():
   num_list=read_list()
   print("Original list entered by user: ")
   print(num_list)
   no_duplicates=remove_duplicates(num_list)
   print("List with duplicates removed: ")
   print(no_duplicates)

main()

Please give a like


Related Solutions

c++ Write a program that will ask the user for three pairs of integer values. The...
c++ Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second. The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
Write a while loop that will let the user enter a series of integer values and...
Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user backwards. do Loop...
ARDUINO Create a function that will ask the user to enter the values for each of...
ARDUINO Create a function that will ask the user to enter the values for each of the three colors (red, green and blue) between 0 and 255. The function should check that the user does not enter a number bigger than 255 or smaller than 0. If this happens, the function should keep asking for a valid number.
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
Write a Python function that will do the following:1. Ask the user to input an integer...
Write a Python function that will do the following:1. Ask the user to input an integer which will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers).2. Determine whether each element is an even number or an odd number3. Return a list of five-string elements "odd" and "even" that map the indexes of the elements of the input list,...
Write a Python function that will ask the user for an integer X bigger than 20...
Write a Python function that will ask the user for an integer X bigger than 20 and return a list "ls" of 10 distinct random integers taken between the interval 0, to X. None of the 10 elements of "ls" should be repeated.
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be...
Instructions JAVA PROGRAMMING 1. Ask the user for a year input (positive integer - should be between 1500 and 2019, inclusive). 2. If the year input is not between 1500 and 2019, do not check for leap year, rather print that this year cannot be checked. 3. Take a year input from the user (should be between 1500 and 2019) 4. If the input year is a leap year, print that year is a leap year; otherwise, print that the...
def main():     # keeping asking user for a word or name until user enters 0    ...
def main():     # keeping asking user for a word or name until user enters 0     while True:         word = input('Enter a word/name to convert (enter 0 to quit): ').upper()       if word == '0': break         print(convert_to_soundex(word)) Whenever i try to run the program it tells me unintend doesn't match any outer identation level !!!!
Write a program to ask three options to the user and continue until user selects option...
Write a program to ask three options to the user and continue until user selects option 3. The first two options prompt a user to enter a string of numbers separated by spaces which is a 2by2 matrix. Do addition and subtraction on the input matrices when user selects 1 and 2. You must write functions for matrix addition, subtraction and print. You may use the following function str_to_mlist to convert string to a list. code example is given: def...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT