In: Computer Science
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
CODE:
def returnDuplicateOnce(numbers:list):
#traversing the list
for i in numbers:
#if the current number in the list is repeated once or appears only
twice in
#the list, then that number is returned
if(numbers.count(i) == 2):
return i
return None
def main():
#list of numbers
numbers = [1,1,1,24,24,6,3,6,3,6,3]
#calling the function
print('Numbers in the list repeated
once:',returnDuplicateOnce(numbers))
#calling the main function
if __name__ == '__main__':
main()
____________________________________________
CODE IMAGES AND OUTPUT:
______________________________________________
Feel free to ask any questions in the comments section
Thank You!