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
Is a system software that manages the hardware resources and provides services 5o the application software
Alborosie

Answer:

"Operating system" is the right response.

Explanation:

  • The key program collection on something like a computer device that maintains it interacts mostly with underlying hardware of that system is considered as an Operating system.
  • Even without the need for an OS, every consumer isn't able to access either equipment, monitor as well as portable phone or devices.
8 0
3 years ago
Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. A boolean variable named recalled has be
fenix001 [56]

Answer:

lknjokjbhib

Explanation:

jjbnikjjk jk  

8 0
3 years ago
Why are id thieves hard to catch?
Paladinen [302]
Because they will change their identity and therefore they will never have the same name for a long period of time . So when they commit a crime , they will be difficult to find and catch
5 0
3 years ago
What would happen to a eukaryotic cell if all its mitochondriawere destroyed
julsineya [31]
The cell won't reproduce ATP.
4 0
3 years ago
True false you cannot fill in a callout​
Svetllana [295]
??????? Can you explain the question some more
8 0
3 years ago
Other questions:
  • Jessica wants to purchase a new hard drive. She wants a drive that has fast access because she will use it to edit videos on her
    12·1 answer
  • Question: Can a single switch port handle two mac addresses?
    8·1 answer
  • What is the slide sorter view used for?
    11·1 answer
  • Which of the following keys open the spelling and Grammer dialog box
    6·1 answer
  • What is it with the order of operations
    9·1 answer
  • What is a phonograph?
    15·2 answers
  • The market is in <br> until the price of goods reflects equal supply and demand.
    10·1 answer
  • Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask
    9·1 answer
  • Betty was sitting at a coffee shop reading her favorite book. She heard an explosion nearby. In a few, she could hear ambulance
    7·2 answers
  • Does anyone know how to permanently delete photos on a dell computer? For my cousin.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!