Question: Write a python code to generate following output: a ) GENERATE 5 0 0 0 RANDOM AND UNIQUE NUMBERS AND SORT THEM b ) ASK

Write a python code to generate following output:
a) GENERATE 5000 RANDOM AND UNIQUE NUMBERS AND SORT THEM
b) ASK USER FOR 1 RANDOM NUMBERS BETWEEN THOSE RANDOM NUMBERS AND FIND OUT WHERE DOES THE RANDOM MUMBER LIES BETWEEN
sUPPOSE RANDOM NUMBER =300 IT SHOULD SHOW IT LIES BETWEEN 299 AND 301
this is my code:
import random
# Generate unique numbers
unique_numbers = set()
while len(unique_numbers)<5000:
unique_numbers.add(random.randint(0,20000))
# Convert set to list
a = list(unique_numbers)
# Selection sort
for i in range(len(a)):
for j in range(i+1, len(a)):
if a[i]> a[j]:
a[i], a[j]= a[j], a[i]
print("After sorting:", a)
n = int(input('Enter a random number: '))
start =0
end = len(a)-1
found =-1
while start<=end:
mid =(start+end)//2
if a[mid]==n:
found = mid
break
if a[mid]>n:
end = mid-1
else:
start = mid+1
print('Found at ',found)
I am unsure about the second part. Can you please check my code and modify the code and show me that the code is working on python IDE. DONT JUST WRITE THE CODE.THANKS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!