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
Access data is _______ in a Word document.
Naya [18.7K]
I believe the answer is embedded. but make sure to check multiple sources.
5 0
3 years ago
What helps in determining the reliability of a person to repay debt?
faust18 [17]

C. The amount of credit score

3 0
3 years ago
Read 2 more answers
What is ambient sound, and what is its purpose in film? When can it be a drawback ?
Helen [10]

Answer:

Ambient sound is an environmental sound or surrounding sounds. They use this kind of sound to give a film's scene credence(belief in or acceptance of something as true). When the sound starts to become distracting to the audience the drawback is used.

Explanation:

6 0
3 years ago
How do you create a reference page in apa format with all websites?
Gre4nikov [31]
Use Cite This For Me's APA citation generator to create a reference page in APA format with all websites.
6 0
3 years ago
A ____ database supports data distributed across several different sites.
Tcecarenko [31]
The blank is supposed to be "distributed" so the sentence goes like this "A distributed database supports data distributed across several different sites"<span />
5 0
3 years ago
Other questions:
  • To locate something in the database, one must type in the keyword into the ________ of the application.
    12·1 answer
  • is family mobile and boost mobile the same? if not whats the difference? (btw this is a random question)
    12·2 answers
  • What happens if you never confirm your facebook account?
    8·1 answer
  • Renting provides _________ flexibility but can lead to _________ costs in the long-term.
    14·2 answers
  • When configuring services, what linux directory typically contains server configuration files?
    8·1 answer
  • Adjusting the ______ adjusts the difference in appearance between light and dark areas of the photo.​
    10·2 answers
  • An automotive engine's camshaft rotates at
    8·2 answers
  • Why is flash memory considered nonvolatile?
    5·1 answer
  • Which of the following is an accurate definition of a computer system? A computer system consists of the operating system that t
    6·1 answer
  • Stages of reverse engineering
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!