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]
2 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]2 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
Why procedures are used and what must be the lastexecutable instruction in a<br><br> procedure?
Art [367]

Answer:

Procedure are used to create and modifying the programs. Basically, it is grouping of instruction that can be used give direction of the flow of program. Control are given to the next term once the execution of the instruction get over. The steps of procedure are:

procedure are first executed the declaration instruction and then coding the procedure, then it will return to the directories and the last executable instruction is the termination of procedure.

4 0
2 years ago
I need help with the stalk holders project
anygoal [31]

Answer:

A project is successful when it achieves its objectives and meets or exceeds the expectations of the stake­holders. But who are the stakeholders? Stakeholders are individuals who either care about or have a vested interest in your project. They are the people who are actively involved with the work of the project or have something to either gain or lose as a result of the project. When you manage a project to add lanes to a highway, motorists are stakeholders who are positively affected. However, you negatively affect residents who live near the highway during your project (with construction noise) and after your project with far-reaching implications (increased traffic noise and pollution).

Explanation:

6 0
3 years ago
Create and apply a CSS class named YellowBackground that selects a yellow background. Apply the class to your HTML file’s body t
RSB [31]

<!DOCTYPE html>

<html>

<head>

 <title>Page Title</title>

</head>

<body class="YellowBackground">

 <style>

    .YellowBackground {

        background-color:yellow;

    }

</style>

</body>

</html>


Like this?

7 0
3 years ago
Smartphones can have virtual keyboards or physical keyboards. What are 3 advantages and disadvantages to each one?
masha68 [24]
Advantages to virtual keyboards:
- You have easy shortcuts
- Cooler emojis <span>
- And we have google voice (or Siri) with a click of a key
Disadvantages to a virtual keyboard: 
- It is very easy to send something you don't want to send by     
     accidentally touching the send button
-  It is harder for people with big hands to use
-  </span>typing speed will likely be negatively impacted on a virtual keyboard<span>.
</span>
Advantages to using a physical keyboard:
- <span> The keyboard takes up no space on the front panel or on the display area.
</span>- <span>you are making use of muscle memory, which increases your speed
</span>- Typing on a touchscreen requires an on-screen keyboard, which lacks the tactile response of a real keyboard.

Disadvantages to using a physical keyboard:
- <span>For the average consumer, phones with a physical keyboard are a bit bulkier.</span>
- Most phones with a physical keyboard have to be designed a certain way to minimize space and increase efficiency.
- I<span>t is a slow method when you need to write a long piece of writing when there are faster ways such as scanning and dictation</span>
5 0
2 years ago
The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the boo
ICE Princess25 [194]

Answer:

float bookExamplePrice = 15.25;

float bookTax = 7.5;

float bookShippingPrice = 2.0;

float Test = bookExamplePrice / 100;

float Tax = Test * bookTax;

float FullPrice = Tax + bookExamplePrice + bookShippingPrice;

// I don't know how to remove the numbers after the first two decimals.

// I tested this program. It works!

// The text after the two slashes don't run when you compile them.

printf("Price: $%.6f\n",FullPrice);

Explanation:

8 0
2 years ago
Other questions:
  • When using the boolean data type, we encapsulate the data in what symbol?
    11·2 answers
  • At which stage should James, a website designer, gather information about the website he wants to create, and at which stage sho
    6·1 answer
  • Which of the following are not deducted on a typical pay stub
    12·1 answer
  • Ann wants to save her presentation so she can work on it later. Which device on her computer can store this data long term?
    14·1 answer
  • Sort short_names in reverse alphabetic order.
    11·1 answer
  • What is the most significant issue that needs to be addressed when ensuring the proper functioning of a computer?
    7·1 answer
  • What happens to a data table when the formulas or variables used to create it are changed?
    9·2 answers
  • Simone needs to add a query for multiple tables in her database. She is using Access 2016. Which tab should she use to add the q
    5·1 answer
  • Explain different types of networking-based attacks
    5·1 answer
  • What command utilizes the limpel-ziv (lz77) compression algorithm and achieves a compression ratio of 60-70 percent?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!