1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valina [46]
3 years ago
10

Write a Python program to do the following: (a)Use a for loop and a random integer generator to generate 5 random integers in 1

to 9. Store the random integers in a list. Display the list. (b)Use a for loop and a random integer generator to generate 5 random integers in 2 to 8. Store the random integers in a second list. Display the second list. (c)Use a for loop to compare elements in the two lists in pairs, i.e., compare the first elements in both lists, compare the second elements in the both lists, etc. Display the larger number in each comparison. The following is an example. There is no user input in this program.
Computers and Technology
1 answer:
Andrei [34K]3 years ago
6 0

Answer:

//program in Python

#library

import random

#part 1

#empty list 1

list1 = []  

#Generate 5 random numbers for the first list

for i in range(0, 5):

   list1.append(random.randrange(1, 9+1))

#print first list

print("First List: " + str(list1))

#part b

#empty list 2

list2 = []  

#Generate 5 random numbers for the second list

for i in range(0, 5):

   list2.append(random.randrange(2, 8+1))

 

#print the second list

print("Second List: " + str(list2))

#part c

#Compare each element from both  lists and print the larger one

print("Larger number in each comparison:")

for i in range(0, len(list1)):

   if list1[i] >= list2[i]:

       print(list1[i])

   else:

       print(list2[i])

Explanation:

Create an empty list.Generate 5 random number from range 1 to 9 and append them  into first list.Create a second empty list.generate 5 random numbers from range  1 to 8 and append them into second list.Print both the list.Then compare both the list an print Larger in each comparison.

Output:

First List: [3, 1, 4, 9, 8]                                                                                                

Second List: [5, 8, 2, 7, 6]                                                                                              

Larger number in each comparison:                                                                                          

5                                                                                                                          

8                                                                                                                          

4                                                                                                                          

9                                                                                                                          

8  

You might be interested in
Images from your .............. can be copied and pasted in a folder on your computer ​
Alenkasestr [34]

I think the answer is document

7 0
3 years ago
Different algorithms can be made to complete the same task in different ways.
musickatia [10]

Answer:

True hope this helps you and everyone!

7 0
3 years ago
Read 2 more answers
Which of the following is NOT a major type of crime reported to the IC3.
mezya [45]
I believe malware fraud, c. 


5 0
3 years ago
Ok so um does anyone know how i can use a divided by sign on computer?
Maslowich
You can just put “/“ to represent dividing
6 0
3 years ago
Read 2 more answers
A token is a special control frame that indicates to the rest of the network that a particular node has the right to transmit da
rusak2 [61]
It is true that a<span> token is a special control frame that indicates to the rest of the network that a particular node has the right to transmit data.</span>
4 0
3 years ago
Other questions:
  • . Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    12·1 answer
  • You are reluctant to write an extra credit book report because you are afraid that your language and punctuation skills are not
    11·1 answer
  • Which of the following is a justification for giving a Page Quality (PQ) rating of Lowest? Select all that apply. True False The
    7·1 answer
  • Write a complete program to do the following: The main program calls a method to read in (from an input file) a set of people's
    12·1 answer
  • Samantha writes technical content for a webpage and uploads it to the webpage. What should she do to ensure that the content, wh
    11·2 answers
  • How designers have created products from waste materials?
    7·1 answer
  • Describe the functions of ALU, resisters, CU, BIU, Cache and FPU.
    7·1 answer
  • How major is the technology problem in the United States?
    15·1 answer
  • ____ the styles allows the designer to start from a known baseline, confident that no unwanted styles will creep in from any bro
    6·1 answer
  • Which file contains full and incremental back-up information for use with the dump/restore utility?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!