Question

In: Computer Science

In the Python: Note 1: You may not use these python built-in functions: sorted(), min(), max(),...

In the Python:

Note 1: You may not use these python built-in functions:

sorted(), min(), max(), sum(), pow(), zip(), map(), append(), count() and counter().

(7 points) unique.py: A number in a list is unique if it appears only once. Given a list of

random numbers, print the unique numbers and their count. Print the duplicate numbers and

their count.

Sample runs:

Enter the size of the list : 7

[8, 2, 6, 5, 2, 4, 5]

There are 3 unique numbers: 8 6 4

There are 2 duplicate numbers: 2 5

Sample run:

Enter the size of the list : 7

[2, 2, 4, 3, 3, 3, 4]

There are 0 unique numbers:

There are 3 duplicate numbers: 2 3 4

Solutions

Expert Solution

CODE

n = int(input("Enter the size of the list : "))

dict = {}

for i in range(n):

el = int(input("Enter the element " + str(i+1) + " : "))

if el in dict:

dict[el] = dict[el] + 1;

else:

dict[el] = 1

unique = 0

duplicate = 0

uniqueNumbers = ""

duplicateNumbers = ""

for key in dict:

if (dict[key] == 1):

unique += 1

uniqueNumbers += str(key) + " "

elif dict[key] > 1:

duplicate += 1

duplicateNumbers += str(key) + " "

print("There are %d unique numbers: %s" %(unique, uniqueNumbers))

print("There are %d duplicate numbers: %s" %(duplicate, duplicateNumbers))


Related Solutions

you may not use the Python ord() or chr() functions you may not use the Python...
you may not use the Python ord() or chr() functions you may not use the Python ord() or chr() functions you may not use the Python ord() or chr() functions You will write a total of four functions, each of which will take two inputs and return a string: c_encrypt() c_decrypt() vig_encrypt() vig_decrypt() The first argument will be a string containing the plaintext (or clear text) message to be encrypted for the two encrypt functions, and a string containing a...
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS....
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS.                          3)Use of string and char is not allowed.             Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256.
1. Open the Salesum document, and add functions to calculate the average, Max, Min and Count...
1. Open the Salesum document, and add functions to calculate the average, Max, Min and Count on rows 18-21 in columns B-E. 2. In Cell B25 type an answer to the following question: Is the average computed in B18-E18 a good predictor of how much a new expense might cost, should we incur a new expense next year? Why or why not?
Directly using mathematical expression, DO NOT USE the built-in Python functions, evaluate the binomial function for...
Directly using mathematical expression, DO NOT USE the built-in Python functions, evaluate the binomial function for n = 20, p = 3/8. Make sure you plot your results (Remember the the binomial distribution is discrete)
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
Write a Python program that computes certain values such as sum, product, max, min and average...
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements. Define a function that takes 5 numbers, calculates and returns the sum of the numbers. Define a function that takes 5 numbers, calculates and returns the product of the numbers. Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the...
Python #For question 1 and 2 you may not use ''' ''' Question 1 Print the messages below without using variables. Output must be 2 lines identical to below: What is the snake's favorite language? "I love Python", said the snake. Question 2 Write a python statements to match the 5 lines of output below. Use a single print statement to produce the list of 4 languages The 3 most popular programming languages of 2020 are: 1.         Python 2.         Javascript 3.         Java 4.         C#...
You can only use built in Lisp functions and you cannot use setq function. Write a...
You can only use built in Lisp functions and you cannot use setq function. Write a function in Lisp called f1 that counts the number of lists in a list. Example: (f1 ‘(a (a b (b c)) c d (e))) returns 2
c++ Write a program that print stars, Max and Min values. It should use the following...
c++ Write a program that print stars, Max and Min values. It should use the following functions: (2 pts) int getNum ( ) should ask the user for a number and return the number. This function should be called by main once for each number to be entered. Input Validation: Do not accept numbers less than -100. (2 pts) void printStars ( int n ) should print n number of stars. If n is less than 0, display "Invalid" message...
Problem 1 (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note....
Problem 1 (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words. Here is how your program should work to simulate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT