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
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...
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: Sublist of list A is defined as a list whose elements are all from...
In Python: Sublist of list A is defined as a list whose elements are all from list A. For example, suppose list A = [0, 1, 2, 3, 4, 5, 6], its has many sublists and one of them is [0, 1, 3] because elements 0, 1 and 3 are all contained in list A. Define a function named returnComplement that accepts two integer lists as the parameter (one of the list is the sublist of the other). Suppose names...
Write a program to swap mth and nth elements of a linked list. Code needed in...
Write a program to swap mth and nth elements of a linked list. Code needed in java.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT