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
In an input file, what maintains the location of the next item that will be read from the file?
Semmy [17]

The Read Position marks the location of the next item that will be read from the file.

6 0
4 years ago
What form of contacts can be shared in Outlook 2016?
ArbitrLikvidat [17]

Answer:

shared contacts

Explanation:

5 0
3 years ago
Read 2 more answers
Program your own file lab7.cpp in which your main() function will test the new data structure. The main() function, Declares an
Stella [2.4K]
Is this a question or just something up here just to be here
3 0
3 years ago
Explains your analysis of the impacts of this new internet distribution on people and businesses.
Anika [276]

Answer:

A business' ability to communicate with its employees, customers and associates changed dramatically when the Internet yielded new communication tools. Email and instant messaging have changed the face of business communication.

8 0
2 years ago
Please help with my Python code - Functions
torisob [31]

Answer:

Explanation:

See attached for assistance

6 0
3 years ago
Other questions:
  • create a 3 to 5 step plan for checking out a post on social media for the next time you encounter something questionable.
    11·2 answers
  • you are configuring a wireless connection on your home router. Because you live in an apartment complex, the level of security i
    5·1 answer
  • Design state machines to control the minutes and hours of a standard 24 hour clock. Your clock should include an AM/PM indicator
    11·1 answer
  • .Prove that f(n) = 3logn + loglogn is capital omega (logn) , what is O(n)?
    8·1 answer
  • Using your own words, explain how third-party cookies are created. Suppose you are an ad-serving company, and you maintain a log
    9·1 answer
  • Give a regular expression for binary numbers. They can be integers or binary fractions. A leading - sign is always allowed. Lead
    15·1 answer
  • True or false. The CPU requires it's own power from the power supply, and can't receive power from the motherboard.
    9·1 answer
  • A client has gathered a very large amount of operational data, but struggles with how to apply Artificial Intelligence (AI) to a
    10·1 answer
  • What is the collection of programs designed to operate control and manage the actual operation of the computer equipment​
    14·1 answer
  • after adding a sound to a slide, the audio tools tab will allow you to apply artistic effects and quick styles to your sound ico
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!