Question

Python: Write a program that performs a sequential search on an ordered list of 1000 elements....

Python: Write a program that performs a sequential search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.

Homework Answers

Answer #1

Please find below code and don't forget to give a Like.

Please refer below screenshot for indentation and output.

Code:

import random
def sequential_search():
#generating random number in range 1 to 1000 to check in list
    random_num=random.randrange(1,1000)
#taking the ordered_list from 1 to 1000 as 1000 elements should be present
    ordered_list=[*range(1,1001,1)]
    a=False
    print("Number we are searching in the order list of (1-1000) is",random_num)
    for i in range(len(ordered_list)):
        if(random_num==ordered_list[i]):
            a=True
            print("Number ",random_num," is found at the position",i)

    if(a==False): #if the element is not found then a will be false 
        print("Number ",random_num," is not found in the list")
sequential_search()

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements....
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.
Write a Python program prints out the unique elements of a list lst in a sorted...
Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
Write a Python program to ask how many elements do users want to create in a...
Write a Python program to ask how many elements do users want to create in a list, then let the user create 2 lists with the number of elements previously entered. Then create and display all combinations of letters, selecting each letter from a different key in a dictionary. Example: How many elements? 2 List 1 = ['a', 'b'] List 2 = ['c', 'd'] Output: ac ad bc bd
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
Write A python program to return all matches for a given search keyword to return the...
Write A python program to return all matches for a given search keyword to return the matched indexes. Hint use string.find(search, begin, end) recursively or in interation
Write a Python program that does the following: Creates a list with the values 2,4,6,8,10 Gets...
Write a Python program that does the following: Creates a list with the values 2,4,6,8,10 Gets a number as input from the user Prints 'in the list' if the input number is a value in the list, and 'not in the list' otherwise
[Python] what are the program solutions to the promts? Write a program to determine which word...
[Python] what are the program solutions to the promts? Write a program to determine which word is the shortest of the following: apple, banana, peach, plum, grapefruit. Write a program to determine the average number given in a list. The first line of your program should give a name to a list to be averaged: e.g numbers = [3,17,1,44,239]
The maximum number of searches required by the binary search algorithm to search an ordered list...
The maximum number of searches required by the binary search algorithm to search an ordered list of n items, where n is a power of 2, what is the time complexity?
In Python write a program that prompts the user for six elements and their atomic numbers...
In Python write a program that prompts the user for six elements and their atomic numbers and stores them in a list. Each element and weight pair should also be a list. After the values have been entered, print the list as it entered. Then print the first two characters from the element names (the first character capitalized and the second in lower case) along with the atomic number, starting with the element with the lowest atomic number. You must...
Write a python program to list all files in the given directory along with their length...
Write a python program to list all files in the given directory along with their length and last modification time. The output should contain one line for each file containing filename, length and modification date separated by tabs. https://www.tutorialspoint.com/python/python_modules.htm
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT