Write a Python program that uses function(s) for writing to and reading from a file:
a. Random Number File Writer Function
Write a function that writes a series of random numbers to a file called "random.txt". Each random number should be in the range of 1 through 500. The function should take an argument that tells it how many random numbers to write to the file.
b. Random Number File Reader Function
Write another function that reads the random numbers from the file "random.txt", displays the numbers, then displays the following data:
The total of the numbers
The number of random numbers read from the file
c. Main Function
Write a main function that asks the user about how many random number the user wants to generate. It them calls the function in a. with the number the user wants as an argument and generates random numbers to write to the file. Next, it calls the function in b.

Answers

Answer 1

import random

def random_number_file_writer(nums):

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

   i = 0

   while i < nums:

       f.write(str(random.randint(1,500))+"\n")

       i += 1

   f.close()

def random_number_file_reader():

   f = open("random.txt", "r")

   total = 0

   count = 0

   for x in f.readlines():

       total += int(x)

       count += 1

   print("The total of the numbers is "+str(total))

   print("The number of random numbers read from the file is "+str(count))

def main():

   random_number_file_writer(int(input("How many random numbers do you want to generate? ")))

   random_number_file_reader()

main()

I hope this helps!


Related Questions

what are the two parts of the uniform resource locator

Answers

Answer:

URL - Uniform Resource LocatorProtocol identifier :  indicates what protocol to use. Resource name :  specifies the IP address .

Explanation:

Answer:

The protocol identifier and the resource name

Explanation:

just did it got a 100%... like for more plz

Who designed the Apple I computer in 1976

Answers

Answer:

Steve Wozniak

Explanation:

Answer:

Steve Wozniak i believe

With __________________________, the IT resource is relocated to a host with more capacity. For example, a database may need to be moved from a tape-based SAN storage device with 4 GB per second I/O capacity to another disk-based SAN storage device with 8 GB per second I/O capacity.

Answers

Answer:

Dynamic Relocation.

Explanation:

The dynamic relocation is one of the methods used to implement a dynamic scalability architecture amongst others such as dynamic horizontal scaling and dynamic vertical scaling.

With dynamic relocation, the IT resource is relocated to a host with more capacity. For example, a database may need to be moved from a tape-based SAN storage device with 4 GB per second I/O capacity to another disk-based SAN storage device with 8 GB per second I/O capacity.

Which ways can you locate a function if you cannot remember the specific name? Check all that apply. searching in the Tell Me bar looking it up in the Formula tab looking it up in the Data tab using the Insert Function and typing a description using the Insert Function and selecting a category

Answers

Answer:

A, B, D, E

Explanation:

Just did it in Edge.

Answer:

A, B, D, E

Explanation:

Jenny has entered data about models of laptops from company A and company B in a worksheet. She enters model numbers of laptops from company A along with their details in different columns of the worksheet. Similarly, she enters details of all the laptop models from company B, Which option will help Jenny view the data for company A and company B in two separate sections after printing? The option will help her view the data for company A and company B in two separate sections after printing.

Answers

Answer:

The Split option under the view tab.

Explanation:

Click the View tab on the Ribbon, then select the Split command. The workbook will be split into different panes. You can scroll through each pane separately using the scroll bars, allowing you to compare different sections of the workbook.

Answer:

Split

Explanation:

Suppose a package pkg1 contains a class named MyClass and another package pkg2 contains a different class named MyClass. What happens when you impot both classes?

Answers

Answer:

Following are the solution to this question:

Explanation:

In this question, two packages "pkg1 and pkg2" is defined, that hold a class that is "MyClass", in which the class name is the same. If we import the package so, it can't import both classes in the very same file. If we really need to apply to both, then must completely specify one class name, and in the class name is different so, we simply use both classes by creating the instance.  

for the following graph, what is the goal state?

Answers

Answer:

E

Explanation:

Answer:

the answer is b

Explanation:

I got it right on the test

In a team if someone gets stuck with the selected tasks for the iteration, what is the immediate next step?

Answers

Answer:

The team member has to immediately inform the lead or onsite coordinator without wasting time and take up another task

Explanation:

In a situation where someone in a team is unable to move further to another tasks the next step is for the team member to immediately inform the onsite coordinator in order for them to take up another task reason been that the onsite coordinator sole responsibility is to ensure the completion of tasks without any flaw and Secondly if the team members did not inform the onsite coordinator immediately it will eventually lead to waste of time due to the time spent on the tasks thereby affecting the next tasks.

Therefore the immediate next step is for the team member to immediately inform the lead or onsite coordinator without wasting time and take up another task.

What are the assignable addresses for the 12th subnet with the network address of 220.100.100.0 and the number of needed subnets is 45? a. 220.100.100.42 to 220.100.100.51 b. 220.100.100.52 to 220.100.100.55 c. 220.100.100.45 to 220.100.100.46 d. 220.100.100.40 to 220.100.100

Answers

Answer:

C. 220.100.100.45 to 220.100.100.46

Explanation:

The Classless IP subnetting of 220.100.100.0 begins from the fourth octet of the IP address. To get 45 subnet mask, it uses 6 bits from the fourth octet, which approximately give 64 subnets, while the remaining 2 bits are used for host IP addressing.

The useable host IP addresses are gotten from the formula '[tex]2^{n}[/tex]-2', with n=2 bits.

useable host IP addresses = 2^2 - 2 = 2 addresses per subnet.

While the 12th subnet is 12 x 2^2 = 44.

This means that the 12th subnet mask starts with 220.100.100.44 (as the network address) and ends with 220.100.100.47 as broadcast IP address, while '.45' and '.46' are the assignable addresses of the subnet.

Identify a security context of interest to you. Within this context, what constitutes a direct benefit of a risk management strategy? An indirect benefit? Provide examples.

Answers

Here,the Preparedness of the National(National Preparedness), that which gives a description of mission areas and also provide a framework for the consideration of management of risk.

It gives an illustration of the relationship of the National preparedness mission elements of risk.

Activities aimed at prevention are also associated with the efforts for the addressing of protection efforts generally address vulnerabilities recovery efforts.

However,we see that efforts of mitigation transcends vulnerability and also consequence spectrum.

Here,the PPD-8 mission areas are central,and this is to enhance national preparedness and also for infrastructure risk management activities.

When these are developed,they contribute to the achievement of resilient and secure critical infrastructure,and these critical infrastructure risks are however seen as part of setting capability targets.

THREAT AND HAZARD IDENTIFICATION AND RISK ASSESSMENT.

"THIRA" gives a provision of an approach for the identification and assessment of risks and also the associated impacts.

Determination that THIRA process has been completed by jurisdiction,then you consider the results when undergoing the assessment of risks to critical infrastructure.

When you are fit, you can exercise and do physical work without getting too tired. A. True B. False\

Answers

Answer:

A.

Explanation:

But all of us get tired

Answer: I did the test it's A

Explanation:

The 0-1 knapsack problem is the following. A thief robbing a store finds n items. The ith item is worth vi dollars and weighs wi pounds, where vi and wi are integers. The thief wants to take as valuable a load as possible, but he can carry at most W pounds in his knapsack, for some integer W . Which items should he take?

Answers

Step by step Explanation:

Based on what we could deduce from the above statement, the items he should take are:

must either take one single item or must leave the other behind,and only a whole amount of an item must be taken,in which an item cannot be taken more than once into his knapsack.

Hence, the thief needs to carefully determine items with an optimal value which still falls within his specified weight (W).

The ____ attribute can be used only with input boxes that store text. Group of answer choices type pattern required value

Answers

Answer:

Pattern.

Explanation:

The pattern attribute can be used only with input boxes that store text.

Generally, the pattern attribute cannot be used with other types of data in computer programming.

Basically, it comprises of data types which mainly includes an attribute of the text, e-mail, telephone, uniform resource locator (URL), search input types and password which must all be matched with the input value in order to pass an authentication or authorization.

Plz help!! ASAP!! And thank you!!

Answers

Answer:

first one, become vulnerable to online harassment

It may be the first one because the other person said so

Which key(s) will launch the Spelling Checker dialog box? F8 F7 Ctrl+H F2

Answers

Answer:

F7

Explanation:

Mostly in MS Office products, although a lot of other products will mimic the same well known key sequences as a way of enticing you to their platform.

Answer:The answer to your question is F7

Explanation:

In a mobile phone network, how many times as strong would

Answers

Answer:

how many times as strong would what?

put your question in the replies to this answer and I'll gladly answer it

Explanation:

May I have brainliest please? :)

Match the definition to the word.
1. establish as law
ordain
2. having the nature of a miracle
retinue
3. a great many
miraculous
4. keep alive and well with food
liege
5. an iron block on which metals are hammered
arms
6. the lord who has the right to homage
multitude
7. a group of attendants
successor
8. weapons; fighting
wrangling
9. a person who follows another person
anvil
10. a noisy quarrel
nourish

Answers

Explanation:

1. establish as law - ordain;

2. having the nature of a miracle - miraculous;

3. a great many - multitude;

4. keep alive and well with food - nourish;

5. an iron block on which metals are hammered - anvil;

6. the lord who has the right to homage - liege;

7. a group of attendants - retinue;

8. weapons - arms;

9. a person who follows another person - successor;

10. a noisy quarrel - wrangling;

Insert in the Current Values section at the top of the worksheet summary functions that use the range I9:I54. In cell I2, calculate the total of all the Current Values. In cell I3, calculate the average current value. in cell I4, calculate the lowest current value. In cell I5, calculate the highest current value

Answers

Answer:

Cell I2: =SUM(I9:I54)

Cell I3: =AVERAGE(I9:I54)

Cell I4: =MIN(I9:I54)

Cell I5: =MAX(I9:I54)

Explanation:

I wasnt able to find the worksheet referenced, however it is not needed to answer correctly.

The question states there are several values in the cell range I9:I54, and we need to perform different operations:

In cell I2, calculate the total of all the Current Values

To obtain the TOTAL calculation, we use the SUM function for all the range of values

=SUM(I9:I54)

In cell I3, calculate the average current value

Average is calculated with the function named the same

=AVERAGE(I9:I54)

In cell I4, calculate the lowest current value

The lowest value of all the range is found with the MIN function

=MIN(I9:I54)

In cell I5, calculate the highest current value

The highest value of all the range is found with the MAX function

=MAX(I9:I54)

John's father specifically asked him to get a magnetic disk from the store in his neighborhood. What should John buy?
A. a floppy disk
B. a DVD
C. a CD-ROM
D. a Blu-ray disk

Answers

Answer:

A floppy disk

Explanation:

A floppy disk uses a thin sheet of magnetic material to store data. It would make the most sense as the other choices use an entirely different system.

Add a data attribute tricks of type list to each Dog instance and initialize it in __init__ to the empty list. The user does not have to supply a list of tricks when constructing a Dog instance. Make sure that you test this successfully. >>> sugar.tricks []

Answers

Answer:

Following are the method to this question:

def __init__(self, _name, _breed):#defining Constructor

       """ Constructor """

       self.name = _name#assigning value in name variable

       self.breed = _breed#assigning value in breed variable

       self.tricks = []#defining tricks an empty list

Explanation:

In the above code, a parameterized constructor is defined, that hold two-variable "name and breed" in its parameter, and another object self is created for storing the value.

Inside the constructor two-variable, and one empty list variable "tricks" is defined that hold value in the name and breed variable, and the next step an empty list is defined, that store its value.

If you are caught in a situation with an active shooter, which order should you plan a safe escape? A. Hide, Fight, Run B. Fight, Run, Hide C. Run, Hide, Fight D. Run, Fight, Hide

Answers

Answer:

The answer is C

Explanation:

the answer is run, hide, fight.

the first thing to do is try and run and get away.

the second thing you should do if you can't run is hide. Then if you can't run away nor hide you have to fight.

Pretty sure it’s C LOL hope dis helps

What sort of technique would you use to sort 10,000 items using just 1000 available slot in your RAM?

a. Heap sort
b. Quick sort
c. Bubble sort

d. Merge sort

Answers

Answer:

d. Merge sort

Explanation:

Merge sort is example of an efficient sorting alogrithm. The Divide and conquer rule is used in this technique. This method breakdown the list into multiple sublists and each sublist contains a single element. This technique merged in the form of sorted lists. This technique uses external memory of the system while sorting.

Merge sort is used to sort the 10,000 items using only 1,000 slots available in the RAM.

__________________ is the capacity for the system to change in size and scale to meet new demands.

Answers

Answer:

The answer is Capacity planning

EMERGENCY- I am giving 55 points for this, please help. WITH working out
What would be the size of a sound file, which is 30 seconds in length and has a bitrate of 96kbps? You must show your working out.

Answers

Answer:

360 kilobytes

Explanation:

(Time × Bitrate) / 8

30 × 96 = 2880 / 8

360 kilobytes

8: kilobits in a kilobyte

Time is always in seconds to obey the kb*ps* rule

Bitrate is always on bits so thats kilobits not kilobytes purpose of conversion

Write a program that uses key events to make a circle larger and smaller.

Your circle should start at a radius of 100 and a position of 250, 250. Each time the user hits the left arrow, the circle should decrease by 10. If the user hits the right arrow, it should increase by 10.

Hint: Use the get_radius() and set_radius() method to change the size of your circle. Find more details and examples on these functions in the DOCs tab.

Challenge: Can you prevent the circle from getting smaller than a radius of 10 and larger than a radius of 400?


in python code

Answers

Answer:

circ = Circle(100)

circ.set_position(250, 250)

circ.set_color(Color.yellow)

add(circ)

def grow_circle(event):

   if event.key == "ArrowLeft":

       circ.set_radius(circ.get_radius() - 10)

   if event.key == "ArrowRight":

       circ.set_radius(circ.get_radius() + 10)

   

add_key_down_handler(grow_circle)

Explanation:

By making it that when the left/right arrow is clicked the radius of the circle is first taking into account before anything else, then each time the arrow is clicked the current radius either gets 10 added or removed from it.    

Write an application that stores the following nine integers in an array: 10, 15, 19, 23, 26, 29, 31, 34, 38. Display the integers from first to last, and then display the integers from last to first.

Answers

Following are the code to this question:

Program Explanation:

Defining an array "arr1" of an integer value is declared, which stores 9 elements. In the next step, an integer variable "i" is declared, which uses two for loops to print the value in the given order.In the first for loop, it starts from 0 and ends when its value is less than 9, and prints the array value.In the second for loop, it starts from 9 and ends when the index value is equal to 0, and prints the array value in reverse order.

Program:

#include <iostream>// header file

using namespace std;

int main()//main method

{

int arr1[]= {10, 15, 19, 23, 26, 29, 31, 34, 38};//defining array of integer values

int i;//defining integer variable

cout<<" Array from first to last: ";//print message

for(i=0;i<9;i++)//use for loop to print array

{

cout<<arr1[i]<<" ";//print array value

}

cout<<"\n Array from last to first : ";//print message

for(i=9-1;i>=0;i--)//defining for loop to print array in reverse order

{

cout<<arr1[i]<<" ";//print array

}

return 0;

}

Output:

Array from first to last: 10 15 19 23 26 29 31 34 38  

Array from last to first : 38 34 31 29 26 23 19 15 10  

Learn more:

brainly.com/question/12906023

Which program will have the output shown below?
10
11
12
13
>>> for count in range(14):
print(count)
>>> for count in range(10,13):
print(count)
>>> for count in range(10, 14):
print(count)
>>> for count in range(13)
print(count)

Answers

Answer:

for count in range(10, 14):

   print(count)

hope i helped :D

Answer:

for count in range(10, 14):

  print(count)

In the Unified Process (UP) methodology, most of the Implementation activities occurs during the _____ phase.

a) Inception

b) Elaboration

c) Construction

d) None of the Above

Answers

Answer:

C) construction

Explanation:

The unified process is one of the software development process frameworks. It is an incremental and iterative software building process. The process is carried out in four phases which include; inception, elaboration, construction and transition.

The construction phase is the largest part and is where most of the implementation activities happen. Here the system features are implemented iteratively to enable the executable release of the software.

What is the output by the code below system.out.print(8-4+2);

Answers

Answer:

6

Explanation:

Its an HTML5 anyone kwons
After the computer executes the following code, what value will be stored in the variable result?

let x = 2, y = 6, z = 5;
let result = (x < 3 && y == 6);

Answers

Answer:

1 will be stored in result

Explanation:

Given

The lines of code

Required

Determine the value stored in result

The value stored in result is determine by the condition (x<3 && y ==6)

In the first line, the value of x is 2 and the value of y is 6

So: x<3 is true because x = 2 and 2 is less than 3

y == 6 is also true because y = 6 and 6 is equal to 6

So, the condition (x<3 && y ==6) is true and true will be saved in variable result

Because result is a Boolean variable which can only take true or false value

1 represents true

0 represents false

So, 1 will be stored in result

Other Questions
1 Subtracting FractionsFind the sum of 57and101oThe expression written in equivalent form with commondenominators isThe sum is Please select the word from the list that best fits the definition The skeletons of tiny ocean animals grow together to form ______, structures that are found only in warm, clear ocean water. Carbohydrates can be used for energy storage or to build structures. Plants store energy as ________A__________ and animals store energy as _______B_________. Plants build structures out of ______C__________. what is the consent term in the expression 6x^3y+8x^2+5x+7 PLZ HELP ME. NO THERE IS NO ANSWER CHOICES. giving brainliest to right answer HELP ME PLZZ I NEED HELP WITH THIS!! The bakers at healthy bakery can make 330 bagels in 5 hours. How many bagels can they bake in 13 hours? what was that rate per hour Which algebraic expression means "four less than three times a number" What can be concluded about triangles RST and VTU?The triangles are congruent and similar with aproportional relationship of 1.The triangles are congruent but not similar.The triangles are similar but not congruent.There is not enough information to determine if thetriangles are congruent or similar Americans grew their own food during World War I to (not a real school question just opinion) What do you think about when you here 'group home' or foster care? If you had control over it, what would you fix, or take away? (look up all types of group homes for more info, if you wish) Factorise: (a) 3x2 + 27y2 + z2 - 18xy + 6 3yz -2 3zx (b) 27 x3 + 125y3 (c) (2a 3b + c )2 (d) 1 a3 + b3 + 125 c3 - 15 a b c (e) [x 1/x y]3 (f) x4 y4 x y 64^4(g) 8x3 (2x y)3 (h) a6 _ b6 Answer please How did Egyptian Religious beliefs impact their lives and afterlife?submission closes after 15 minutes I need this done ASAP Which benchmark demonstrates improvement in body composition?Aincrease muscule mass and a 2% decrease in body fatBincrease in repetitions on push-upsincrease in repetitions on lunges and 5% increase in body weightDincrease time on planks why is it preferable to have a resting heart rate of 70 beats per minute BPM or lower !PLEASE HELP ASAP!How many grams of aluminum can be produced by decomposing 12.3 grams of aluminumoxide? Crane Corporation acquires a coal mine at a cost of $476,000. Intangible development costs total $119,000. After extraction has occurred, Crane must restore the property (estimated fair value of the obligation is $95,200), after which it can be sold for $190,400. Crane estimates that 4,760 tons of coal can be extracted. If 833 tons are extracted the first year, prepare the journal entry to record depletion. (I what is the moral lesson of monkey Paw's Which statement is true of the zero tolerance policy?A. It builds trust between offenders and police officers B. It increases serious crime rates in poor neighborhoodsC. It improves tolerance between victims and offendersD. It immediately takes care of crime in the community what does scrooge want in lines 37 - 39? pls help me on this!!!!! (foolish answers will be reported)Cul es el significado de la visita de estos nueve veteranos estadounidenses aJapn?A. Representa el punto de vista que tienen los japoneses veteranos sobre los veteranos de Estados Unidos a pesar de la reconciliacin de los dos pases.B. Representa el papel que los veteranos estadounidenses tienen en mantener la paz entre Japn y Estados UnidosC. Representa la continua reconciliacin entre los pases de Japn y los Estados Unidos que fueron los principales enemigos durante la Segunda Guerra Mundial.D. Representa una nueva relacin poltica que tienen los pases Aliados y los del grupo del Eje y demuestra que los pases Aliados fueron los que ganaron.