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
Assume that x is a string variable has been given a value. Write an expression whose value is true if and only if x is an hexade
Lady bird [3.3K]

Answer:

import string

all(c in string.hexdigits for c in s)

Explanation:

The hexadecimal number system, often abbreviated as "hex", is a numeral system which consist of 16 symbols (base 16). The standard numeral system we are all use to, called decimal (base 10) and utilizes ten symbols: 0,1,2,3,4,5,6,7,8,9.

Using python programming language

import the  string module

the second expression iterate through the digit in s and confirm if they all are within the rage of 0 -9 ad A -F. If yes , it returns True and else, it returns false

6 0
3 years ago
Give five example of a dedicated device ​
kogti [31]

Common examples are ATMs, POS terminals, and airport ticket vending machines. Cashierless checkout technologies like “Scan and Go,” inventory scanning, corporate-owned work profile devices, self-ordering kiosks, mobile devices, and POS/m POS are some of the most common examples of dedicated devices in use today.

6 0
2 years ago
Read 2 more answers
1. Write a function that will ask the user to enter a value in dollars. The function should calculate and display the equivalent
julia-pushkina [17]

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

   

    valueInDollars();

}

   public static void valueInDollars() {

       double currentMoney, quarters, dimes, nickels, pennies;

       Scanner input = new Scanner(System.in);

       

       System.out.print("Enter a value in dollars: ");

       currentMoney = input.nextDouble();

       currentMoney *= 100;

       quarters = (int)currentMoney / 25;

       currentMoney = currentMoney % 25;

       

       dimes = (int)currentMoney / 10;

       currentMoney = currentMoney % 10;

       

       nickels = (int)currentMoney / 5;

       currentMoney = currentMoney % 5;

       

       pennies = currentMoney;

       

       System.out.print("Quarters: " + quarters + "\n" + "Dimes: " + dimes + "\n" + "Nickels: " + nickels + "\n" + "Pennies: " + pennies);

   }

}

Explanation:

<u>Inside the function:</u>

- Declare the variables

- Ask the user for a value in dollars

- Multiply that value by 100

- Find the amount of quarters, dimes, nickels, and pennies

- Print the values

<u>Inside the main:</u>

- Call the function

3 0
3 years ago
Clicking on this will minimize all open windows.
vfiekz [6]
I believe it is the the Show Desktop Icon.
Hope this helps! <3
4 0
2 years ago
Read 2 more answers
One acre of Land is equivalent to 43,560 square feet. Write a program that ask the user to enter the total square feet of a piec
trapecia [35]

Answer:

#include <stdio.h>

int main() {    

   const float square_feet;

   printf("Enter area in square feets: ");  

   // reads and stores input  area

   scanf("%f", &square_feet);

   float acres= square_feet/43560;

   // displays area in acres

   printf("area in acres is: %.2f", acres);

   

   return 0;

}

Explanation:

code is in C language.

double slashed '//'  lines are  not code but just comments to understand what it mean in code or for explanation purpose

7 0
3 years ago
Other questions:
  • What is the purpose of the BBC option in a email?
    7·1 answer
  • Explain how inflation flattens the universe
    6·2 answers
  • 8) The higher the drag coefficient, the_____ the car will go<br> a)Siower<br> b)Faster
    9·2 answers
  • Some IOS commands store passwords as clear text, but you can then encrypt the passwords with the service password-encryption glo
    10·1 answer
  • In 1971, Intel created and marketed the first microprocessor chip, called the Intel 4004. What was significant about this invent
    7·1 answer
  • Free brainliest!?! &lt;3​
    9·2 answers
  • Davingould1115...................answer 2​
    11·2 answers
  • What is output by the following line of code?
    15·1 answer
  • What plan can businesses use to protect sensitive data from malicious attacks?
    11·2 answers
  • Binary subtraction<br> Subtract (111) from (1000)
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!