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
devlian [24]
3 years ago
15

Write a Python program that uses function(s) for writing to and reading from a file:

Computers and Technology
1 answer:
swat323 years ago
6 0

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!

You might be interested in
Which of the following components was a significant development featured in the Macintosh LISA computer?
Free_Kalibri [48]
I believe that the Apple Lisa computer was the first production microcomputer to have a GUI.
3 0
3 years ago
The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula:
Feliz [49]

Answer: ion k

Explanation:

4 0
3 years ago
The first page of a website is what?​
EleoNora [17]

Answer:

index.html

Explanation:

The name of the html file for the homepage of a website is usually "index.html"

4 0
3 years ago
Read 2 more answers
Can someone write this in java? Also, does anyone know how to do Edhesive assignments?
svetoff [14.1K]
No I don’t know what are you saying can you explain or I’m here for points heheheh and Java is written in any way
7 0
3 years ago
What is software? Why is it needed? ​
sesenic [268]

Computer software, also known simply as software, also known by overseas Vietnamese as software is a collection of data or commands that instruct the computer to tell the computer how to work.  This is in contrast to the physical hardware, from which the system is built and actually does the work.  Because it helps people perform functions that humans can't do or do for a very long time

8 0
3 years ago
Other questions:
  • A cracked tone (reluctor) ring will often cause what type of problem
    13·1 answer
  • What term is used to describe the time it takes a signal to travel from one location to another on a network?
    13·1 answer
  • Using underlining and italics at the same time is which of these? A. allowed but might be overkill B. always a good idea C. not
    15·2 answers
  • In a CPMT, a(n) ____ should be a high-level manager with influence and resources that can be used to support the project team, p
    10·1 answer
  • Design aPayrollclass that has fields for an employee’sname, ID number, hourly pay rate,and number of hours worked. Write theappr
    9·1 answer
  • is a shell program in Windows that holds individual utilities called snap-ins, designed for administration and troubleshooting.
    11·1 answer
  • 100 in hexadecimal then. binary
    11·1 answer
  • How do you detect my account for brainly?
    14·1 answer
  • Match the feature to its function.
    7·1 answer
  • 1. As part of your community, your school, and your neighbourhood, how else does ICT have an impact on social
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!