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
Which option should you select to ignore all tracked changes in a document? To ignore all tracked changes in a document, you sho
garri49 [273]

Track Changes is a way for Microsoft Word to keep track of the changes you make to a document.To ignore all tracked changes in a document, you should select the Final option, on the Track Changes tab in the Review tab.

On the Review tab, use the little menus in the Tracking group. Final: Show Markup or Original: Show Markup will show what changes you have made.

6 0
3 years ago
Read 2 more answers
Maggie is preparing a business report. Which types of keys will she use to type out words and numbers?
nadya68 [22]
She would use enter period comma backspace
Hope this helps u
6 0
3 years ago
Read 2 more answers
High-speed memory that reduces the frequency of access by the cpu to conventional memory is called
lidiya [134]
Your answer would be "cache memory."
5 0
3 years ago
Write a program code which asks for 80 numbers between 100 and 1000 to be entered.
Firlakuza [10]

Answer:

If you are using Python,

```count = 0

for i in range(0, 79):

a = int(input("Input a number: "))

if 100 <= a <= 1000:

 if a > 500:

  count += 1

else:

 print("Please input a number between 100 and 1000!")

 i -= 1

print(count)```

Explanation:

count refers to the number of 500s and above,

the for loop is required for the program to loop 80 times,

a is the input collected,

the nested if is to check whether the number is above 500 and the if is used to check if the number is between 100 and 1000 if not, it will output that you need to input a number between 100 and 1000,

the i-=1 is required to make sure that part wasn't counted.

and the last print is to output the number of numbers above 500

8 0
3 years ago
When powering off your computer is best down using?
MAXImum [283]

command prompt shutdown/s or alt f4


7 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is considered information?
    6·2 answers
  • vulnerability is a feebleness which allows an attacker to condense a system's information assurance to security,is it true or fa
    14·1 answer
  • Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05
    9·1 answer
  • Select the correct answer.
    15·1 answer
  • What are the trinity of the computer system
    10·1 answer
  • Assume that class BankAccount exists, and that it has a constructor that sets the private field balance, and that setBalance and
    13·1 answer
  • Who is tim berners-lee
    14·2 answers
  • computer is an electronic machine that is used for data processing to produce meaningful information explain in statement​
    5·1 answer
  • I want to start a debate about something
    9·2 answers
  • A statement that starts with a # symbol is called
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!