Create a program that writes a series of random numbers to a file, then reads the file to calculate the average of those numbers, as well as the highest and lowest numbers. Prompt the user for how many random numbers they want to add to file. If the number is less than 100, add at least 100 numbers. Each random number should be between 10 and 500, inclusive (at least 10, no more than 500). Create the file as YourName_randomnumbers.txt (where YourName is your actual name or initials...) Once the program creates the file, open and read in all numbers. Loop through the numbers and determine the highest number, the lowest number, count how many entries are in the file, and calculate the average of all numbers. Remember to use functions and comment as needed. Submit your .py file and your randomnumbers.txt file.

Answers

Answer 1

Answer:

In Python:

import random

def average(content):

sum = 0

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

 content[i] = int(content[i])

 sum = sum + content[i]

print("Average: "+str(round(sum/len(content),2)))

def maxList(content):

print("Highest: "+str(max(content)))

def minList(content):

print("Lowest: "+str(min(content)))

f = open("YourName_randomnumbers.txt", "w")

num = int(input("Random Numbers: "))

if num < 100:

num = 100

for i in range(1,num+1):

f.write(str(random.randint(10,500)))

f.write(" ")

f.close()

with open('YourName_randomnumbers.txt') as ff:

content = ff.read().split()

print("Entries: "+str(len(content)))

average(content)

maxList(content)

minList(content)

Explanation:

First, we import the random module

import random

The program uses functions. The first is the average function

def average(content):

This initializes sum to 0

sum = 0

This iterates through the list and adds up the list elements

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

 content[i] = int(content[i])

 sum = sum + content[i]

This prints the average, rounded to 2 decimal places

print("Average: "+str(round(sum/len(content),2)))

The maxList function begins here

def maxList(content):

This gets and prints the highest of the list

print("Highest: "+str(max(content)))

The minList function begins here

def minList(content):

This gets and prints the lowest of the list

print("Lowest: "+str(min(content)))

The main begins here

This createa a file and prepares it for write operations

f = open("YourName_randomnumbers.txt", "w")

This prompts user for number of random numbers

num = int(input("Random Numbers: "))

If user input is less than 100

if num < 100:

It is set to 100

num = 100

The following iteration generates random numbers between 10 and 500 and inserts the random number to file

for i in range(1,num+1):

f.write(str(random.randint(10,500)))

f.write(" ")

Close file

f.close()

The following iteration reads the file content into a list

with open('YourName_randomnumbers.txt') as ff:

content = ff.read().split()

This prints the number of entries

print("Entries: "+str(len(content)))

The next three instructions calls the average, maxList and minList functions respectively

average(content)

maxList(content)

minList(content)


Related Questions

Write a java program for the following
A student will not be allowed to sit in exam if his/her attendance is less than 75% .
Take the following input from user
Number of classes held
Number of classes attended
And print
Percentage of class attended
Is student allowed to sit in exam or not .

Answers

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 

 Scanner input = new Scanner(System.in);

 

 int classesHeld, classesAttended;

 double percentage;

 

 System.out.print("Enter number of classes held: ");

 classesHeld = input.nextInt();

 

 System.out.print("Enter number of classes attended: ");

 classesAttended = input.nextInt();

 

 percentage = (double) classesAttended / classesHeld;

 

 if(percentage < 0.75)

     System.out.println("You are not allowed to sit in exam");

 else

     System.out.println("You are allowed to sit in exam");

}

}

Explanation:

Import the Scanner to be able to get input from the user

Create a Scanner object to get input

Declare the variables

Ask the user to enter classesHeld and classesAttended

Calculate the percentage, divide the classesAttended by classesHeld. You also need to cast the one of the variable to double. Otherwise, the result would be an int

Check the percentage. If it is smaller than 0.75 (75% equals 0.75), print that the student is not allowed. Otherwise, print that the student is allowed

When using the Mirror command you can delete the source object as the last step of the command. True or false

Answers

Answer:

The anwser is true it is true.

when food material are preserved at a temperature just above freezing the temperature process is called​

Answers

It’s freezing. The process is called freezing

What’s the difference packet switching and message switching??

Answers

Im not sure but the person above is right x :)))


Explanation dudjdb

What are the WORST computer malware in your opinion it can be worms backdoors and trojans I just want a input, nothing right or wrong

Answers

Answer:

I think probably mydoom

Explanation:

as it estimated 38 billion dollars in damage, also this malware is technically a worm

The ABC box company makes square puzzle cubes that measure 4 inches along each edge. They shipped the cubes in a box 8 in x 12 in x 16 in. How many cubes can they ship in the box?

Answers

Answer: They can ship 32 puzzle cubes in the box.

Explanation: So the volume of each puzzle cubes = side³

=(4)³ cubic inches.

Then the volume of the box is= (8×12×16) cubic inches.

(8×12×16)/4^3= 32

Which heading size fits for the word headings​

Answers

Answer:

Explanation:

h1 i think

What would a bar graph best be used for? State why and give 2-3 examples of things you could demonstrate with a bar graph.

Answers

Answer:

Reasons what bar graph is used for.

Explanation:

Bars are shown to compare and contrast data in a bar graph. For example, a data was collected through survey of average rainfall. It represents many unique categories by having many different groups. Those groups are plotted on the x-axis and on the y-axis, the measurements are plotted, like inches.

Hope this helps, thank you !!

A broadband connection is defined as one that has speeds less than 256,000 bps.
Question 25 options:
True
False

Answers

Answer:

A typical broadband connection offers an Internet speed of 50 megabits per second (Mbps), or 50 million bps.

Explanation:

I think I got it right, plz tell me if im wrong

Create a flowchart that assigns a counselor to a student.
You need to ask a student for the first letter of his/her last name. Assign a counselor based on the following criteria:
A through M are assigned to Ms. Jones
N through Z are assigned to Mr. Sanchez

Answers

Please Help! Unit 6: Lesson 1 - Coding Activity 2
Instructions: Hemachandra numbers (more commonly known as Fibonacci numbers) are found by starting with two numbers then finding the next number by adding the previous two numbers together. The most common starting numbers are 0 and 1 giving the numbers 0, 1, 1, 2, 3, 5...
The main method from this class contains code which is intended to fill an array of length 10 with these Hemachandra numbers, then print the value of the number in the array at the index entered by the user. For example if the user inputs 3 then the program should output 2, while if the user inputs 6 then the program should output 8. Debug this code so it works as intended.

The Code Given:

import java.util.Scanner;

public class U6_L1_Activity_Two{
public static void main(String[] args){
int[h] = new int[10];
0 = h[0];
1 = h[1];
h[2] = h[0] + h[1];
h[3] = h[1] + h[2];
h[4] = h[2] + h[3];
h[5] = h[3] + h[4];
h[6] = h[4] + h[5];
h[7] = h[5] + h[6];
h[8] = h[6] + h[7]
h[9] = h[7] + h[8];
h[10] = h[8] + h[9];
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
if (i >= 0 && i < 10)
System.out.println(h(i));
}
}

2. You are developing a new application that optimizes the processing of a warehouse’s operations. When the products arrive, they are stored on warehouse racks. To minimize the time it takes to retrieve an item, the items that arrive last are the first to go out. You need to represent the items that arrive and leave the warehouse in a data structure. Which data structure should you use to represent this situation?
a) array
b) linked list
c) stack
d) queue

Answers

Answer:

Option d) is correct

Explanation:

To optimize the processing of a warehouse’s operations, products are stored on warehouse racks when they arrive. The items that arrive last are the first to go out to minimize the time it takes to retrieve an item. The items that arrive need to be represented and the warehouse should be left in a data structure. The data structure which should you use to represent this situation is a queue.

Option d) is correct

Write a program which will enter information relating to a speeding violation and then compute the amount of the speeding ticket. The program will need to enter the posted speed limit, actual speed the car was going, and whether or not the car was in a school zone and the date of the violation. Additionally, you will collect information about the driver (see output for specifics). The way speeding tickets are computed differs from city to city. For this assignment, we will use these rules, which need to be applied in this order:

Answers

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 float speedlimit, actualspeed;

 String ddate;

 int schoolzone;

 System.out.print("Speed Limit: ");

 speedlimit = input.nextFloat();

 System.out.print("Actual Speed: ");

 actualspeed = input.nextFloat();

 System.out.print("Date: ");

 ddate = input.nextLine();

 System.out.print("School Zone (1-Yes): ");

 schoolzone = input.nextInt();

 float ticket = 75;

 ticket += 6 * (actualspeed - speedlimit);

 

 if(actualspeed - speedlimit > 30){

     ticket+=160;

 }

 if(schoolzone == 1){

     ticket*=2;

 }  

 System.out.print("Date: "+ddate);

 System.out.print("Speed Limit: "+speedlimit);

 System.out.print("Actual Speed: "+actualspeed);

 System.out.print("Ticket: "+ticket);

}

}

Explanation:

See attachment for complete program requirements

This declares speedlimit and actualspeed as floats

float speedlimit, actualspeed;

This declares ddate as string

 String ddate;

This declares schoolzone as integer

 int schoolzone;

This prompts the user for speed limit

 System.out.print("Speed Limit: ");

This gets the speed limit

 speedlimit = input.nextFloat();

This prompts the user for actual speed

 System.out.print("Actual Speed: ");

This gets the actual speed

 actualspeed = input.nextFloat();

This prompts the user for date

 System.out.print("Date: ");

This gets the date

 ddate = input.nextLine();

This prompts the user for school zone (1 means Yes, other inputs means No)

 System.out.print("School Zone (1-Yes): ");

This gets the input for schoolzone

schoolzone = input.nextInt();

This initializes ticket to $75

 float ticket = 75;

This calculates the additional cost based on difference between speed limits and the actual speed

 ticket += 6 * (actualspeed - speedlimit);

If the difference between the speeds is greater than 30, this adds 160 to the ticket  

 if(actualspeed - speedlimit > 30){

     ticket+=160;

 }

If it is in a school zone, this doubles the ticket

 if(schoolzone == 1){

     ticket*=2;

 }  

The following print the ticket information

 System.out.print("Date: "+ddate);

 System.out.print("Speed Limit: "+speedlimit);

 System.out.print("Actual Speed: "+actualspeed);

 System.out.print("Ticket: "+ticket);

Compression algorithms vary in how much they can reduce the size of a document.
Which of the following would likely be the hardest to compress?
Choose 1 answer:

A. The Declaration of Independence

B. The lyrics to all of the songs by The Beatles

C. A document of randomly generated letters

D. A book of nursery rhymes for children

Answers

b the lyrics to all of the songs by the beatles !

The statement that represents the thing that would likely be the hardest to compress is a document of randomly generated letters. Thus, the most valid option for this question is C.

What is an Algorithm?

An algorithm may be characterized as a type of methodology that is significantly utilized for solving a problem or performing a computation with respect to any numerical problems.

According to the context of this question, an algorithm is a set of instructions that allows a user to perform solutions with respect to several numerical and other program-related queries. It can significantly act as an accurate list of instructions that conduct particular actions step by step in either hardware- or software-based routines.

Therefore, the statement that represents the thing that would likely be the hardest to compress is a document of randomly generated letters. Thus, the most valid option for this question is C.

To learn more about Algorithms, refer to the link:

https://brainly.com/question/24953880

#SPJ3

Define a function roll() that takes no arguments, and returns a random integer from 1 to 6. Before proceeding further, we recommend you write a short main method to test it out and make sure it gives you the right values. Comment this main out after you are satisfied that roll() works.

Answers

Answer:

Follows are the code to this question:

#include <iostream>//defining a header file

using namespace std;

int roll()//defining a method roll

{

return 1+(rand() %5);//use return keyword that uses a rand method

}

int main()//defining main method

{

cout<<roll();//calling roll method that print is value

return 0;

}

Output:

4

Explanation:

In this code,  the "roll" method is defined, that uses the rand method with the return keyword, that returns the value between 1 to 6, and in the next step, the main method is declared, that uses the print method to calls the roll method.

who likes tom holland as spiderman and his web shooter tippets when he swings off buildings in new york city midtown, Forest Hills and he is a superhero and I am his humongous fan of spiderman or peter parker the spider man

Answers

Answer:

YESSSS!!!!

Explanation:

Answer:

ayo no spikar english :u

I need help for my computer science class I would appreciate it

Answers

Answer:

21

Explanation:

a = 7

b = 7

c = 2

7 is greater than or equal to 7 , so it will return 7 + 7 *2 which is 21

Changing the color of the text in your document is an example of

Answers

Answer:

???????????uhhh text change..?

Explanation:

Answer:

being creative

Explanation:

cause y not?

Use the drop-down menus to explain what happens when a manager assigns a task in Outlook.
1. Managers can assign tasks to other users within_______ .
2. Once the task is assigned, Outlook__________ the assignment to that user.
3. The user must_______ the task to have it placed in their_________ .

Answers

Answer:

1. an organization

2. emails

3. accept

4. to-do list

Explanation: edge

Answer:Use the drop-down menus to complete statements about assigning tasks in Outlook.

A Task Request form is an interactive way to assign tasks to

✔ Outlook users

and report updates on the status of an assigned task.

An assigned task sends

✔ an email

request for the user to accept or decline and sends

✔ an automated response message

to the assigner.

Explanation:

Write a program called clump that accepts an ArrayList of strings as a parameter and replaces each pair of strings with a single string that consists of the two original strings in parentheses separated by a space. If the list is of odd length, the final element is unchanged. For example, suppose that a list contains

Answers

Answer:

In Java:

public static void clump(ArrayList<String> MyList) {  

   for(int i = 0; i<MyList.size()-1;i++){

       String newStr = "(" + MyList.get(i) + " "+ MyList.get(i + 1) + ")";

  MyList.set(i, newStr);

  MyList.remove(i + 1);

   }

       System.out.println("Updated ArrayList: " + MyList);

 }

Explanation:

First, we define the method

public static void clump(ArrayList<String> MyList) {  

Next, we iterate through the ArrayList

   for(int i = 0; i<MyList.size()-1;i++){

This clumps/merges every other ArrayList element

       String newArr = "(" + MyList.get(i) + " "+ MyList.get(i + 1) + ")";

This updates the elements of the ArrayList

  MyList.set(i, newArr);

This removes ArrayList elements at odd indices (e.g. 1,3...)

  MyList.remove(i + 1);

   }

This prints the updated List

       System.out.println("Updated ArrayList: " + MyList);

 }

Which of the following is the best way to keep up with trends in your industry?
Read the newspaper
Watch the news
Conduct scholarly research
Use social media

Answers

Answer:

Use social media

Explanation:

Social media has significantly helped to bridge gaps in the communication as end users are able to send and receive messages in real-time without any form of delay. Also, social media platforms facilitate the connection of friends, families, co-workers and brands with one another by sharing memories, innovations, new technologies, knowledge and ideas without being physically present in the same location through the use of social network services such as Face-book, Insta-gram, Twitter, LinkedIn, Zoom, Sk-ype, Hangout, You-Tube, etc.

Hence, the best way to keep up with trends in your industry is to through the use of social media because you get to see and learn from trending ideas, methods of production, technologies, and innovations that are being posted from time to time.

Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how many rooms the hotel has, how many of them are occupied, and the percentage of rooms that are occupied.

Answers

Answer:

In Python:

floor = int(input("Number of floors: "))

totalrooms = 0

totaloccupied = 0

for i in range(floor):

   rooms = int(input("Rooms in floor "+str(i+1)+": "))

   occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))

   totalrooms = totalrooms + rooms

   totaloccupied = totaloccupied + occupied

   

print("Total Rooms: "+str(totalrooms))

print("Total Occupied: "+str(totaloccupied))

print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")

Explanation:

This line prompts the user for number of rooms

floor = int(input("Number of floors: "))

This line initializes totalrooms to 0

totalrooms = 0

This line initializes totaloccupied to 0

totaloccupied = 0

This iterates through the floors

for i in range(floor):

This gets the number of rooms in each floor

   rooms = int(input("Rooms in floor "+str(i+1)+": "))

This gets the number of occupied rooms in each floor

   occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))

This calculates the total number of rooms

   totalrooms = totalrooms + rooms

This calculates the total number of occupied rooms

   totaloccupied = totaloccupied + occupied

   

This prints the total number of rooms

print("Total Rooms: "+str(totalrooms))

This prints the total number of occupied rooms

print("Total Occupied: "+str(totaloccupied))

This prints the percentage of occupied rooms to 2 decimal places

print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")

A marketing plan includes a number of factors, including the marketing mix.
What is the marketing mix?
A. The variables of product, price, place, and promotion
B. Using names and symbols to ideny the company's products
C. How the company intends for customers to view its product
relative to the competition
D. A plan for spending money
SUBMIT

Answers

A marketing plan includes a number of factors, including the marketing mix.
What is the marketing mix?
A. The variables of product, price, place, and promotion

why was the 80s bad for Disney i know one example but ill tell you after you answer

Answers

Answer:

The dark stories behind it? i dont  know lol

What should Stephan do to improve his study environment? Check all that apply. remove distracting technology have easy access to his study resources ask his parents to leave the room leave some food and drink for snacks while studying allow his dad to stay only if he is helping with studying remove all food and drink from the room​

Answers

Answer:

I. Remove distracting technology.

II. Have easy access to his study resources.

III. Allow his dad to stay only if he is helping with studying.

Explanation:

A study environment can be defined as a place set aside for reading and studying of educational materials.

In order to facilitate or enhance the ability of an individual (student) to learn and assimilate information quickly, it is very important to ensure that the study environment is devoid of any form of distraction and contains the necessary study materials (resources).

Hence, to improve his study environment, Stephan should do the following;

I. Remove distracting technology such as television, radio, games, etc.

II. Have easy access to his study resources. Stephan shouldn't keep his study materials far away from his study area.

III. Allow his dad to stay only if he is helping with studying.

Answer:the person above it right

Explanation:

Write VHDL code for the circuit corresponding to an 8-bit Carry Lookahead Adder (CLA) using structural VHDL (port maps). (To be completed before your lab session.)

Answers

Answer:

perdo si la pusiera es español te ayudo pero no esta en español

I need help I would really appreciate it

Answers

Answer:

Checks if it is a multiple of 3 and 5

Explanation:

Its an if statement using modulus division to check for a remainder. It checks if a number is a multiple of 3 AND 5. (&& and & both mean and in Java).

If the remainder of both is 0 then that means the mystery number is a multiple of both 3 and 5.

Which statements about editing an existing Contact in Outlook are true? Check all that apply.

Double-click a contact to open the editing page.
Right-click a contact and click Edit to open the editing page.
Click the Edit link in the Contact Information page to open the editing page.
Contacts can be edited in the body of an email message.
Existing fields can be edited for a Contact in the editing page.
New fields can be added for a Contact on the editing page.

Answers

Answer:

Double-click a contact to open the editing page.

Right-click a contact and click Edit to open the editing page.

Click the Edit link in the Contact Information page to open the editing page.

Existing fields can be edited for a Contact in the editing page.

New fields can be added for a Contact on the editing page.

Explanation:

just did it

The following statements should be considered for editing into an existing contact in Outlook:

Double click the contact in order to open the editing page.Right-click the contact & click on edit to open the editing page.Click on the edit link in the page of contact information for editing the page.The fields that are existed could be altered for a contact in an editing page.The new fields for the contact on the editing page could be added.

The following information should be relevant:

The Contact & editing page is important.Contacts can't be added to the body of the email message.

Therefore we can conclude the above statements should be considered for altering an existing contact in outlook.

Learn more about the outlook here: brainly.com/question/20494929

State whether the data described below are discrete or​ continuous, and explain why. The durations of movies in seconds

Answers

Answer:

the data are continuous because the data can take any value in an interval.

Wilma is looking for facts about social media for her research project. What fact should she use for her project?

1: Communicating with social media is hard
2: Social media is a great way to communicate.
3: Social media is fun and easy to use.
4:The minimum age for some social media sites is 13.

Answers

the fact she should use for her project is number 4 because that’s the only fact, the rest are opinions!

Which of these is NOT a mathematical operator used in Python?

A. !
B. /
C. %
D. *

Answers

the answer is A. i wouldn’t seen any mathematical question that has to do with “!”
Other Questions
what did Garret Morgan do for a living ,dont look it up! name the steps on How a Bill Becomes a law? Which graph represents the solution set of the inequality Negative 14.5 less-than x?A number line going from negative 15 to negative 11. An open circle is at negative 13.5. Everything to the right of the circle is shaded.A number line going from negative 15 to negative 11. A closed circle is at negative 14. Everything to the right of the circle is shaded.A number line going from negative 15 to negative 11. An open circle is at negative 14.5. Everything to the right of the circle is shaded. A number line going from negative 15 to negative 11. A closed circle is at negative 15. Everything to the right of the circle is shaded. Geometry Substitution Im confused on how to substitute can someone give me a step by step explanation! Please Why isnt deep groundwater readily available for human use? What is one main feature of the free enterprise system? System of government in which the citizens vote for the leader indirectly. The leader is chosen by the legislative branch (usually called the parliament). Presidential DemocracyRepresentative DemocracyParliamentary DemocracyFederal The cost for an eighth-grade party is $450 for room rental, entertainment, anddecorations, plus $20 per person for food. Tickets for the party are sold for $25. What isthe break-even point? "I challenge the warmest advocate for reconciliation to show a single advantage that this continent can reap by being connected with Great Britain. I repeat the challenge; not a single advantage is derived. Our corn will fetch its price in any market in Europe......" An Analyst wants to know if there was a significant difference in the average of hours worked in a week from 2000 (Group 1) to 2004 (Group 2). He gathers all the data from the General Social Survey, and lists the following summary statistics from the sampling. Year 2000 2004Mean 27.34 48.12Std. Dev 10.11 19.23Unweighted n 43 54Required:What is the correct null hypothesis? If you run with an average speed of 3.9 meters per second for 1,200 seconds, then what distance will you have traveled? Is the equation y=3x in slope-intercept form? Explain. The equation y=3x in slope-intercept form. Question 2 The slope is and the y-intercept is a . if you only have 14 packs of Fire Works and my 3 friends and I sent them off how many packs does each of us get if we share them equally What is the slope of the line that passes through the points (-6, -7) and(-24. - 7)? Write your answer in simplest form. Cuales son los nombres Hispanos deSken, Prodos, Koilon, Proskenion, Prohedia y Orchesta?La pregunta es de literatura pero no encuentro un tag para literatura In what country can the Blue Mosque of Istanbul be found? Is a Heterotroph a araebacteria or a eubacteria 13) How many moles of CH3NH2 can be producedfrom 24 moles of N2? Pleaseeee help !!!!!! the quotient of a number m and 4