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
If you wanted to create a line of code that would add ten to the user’s current score, which code should you use?
Korvikt [17]

Answer:

choice c

Explanation:

score = score + 10

because the rest doesn't make since and score == score + 10 has an extra equal sign.

7 0
2 years ago
Read 2 more answers
⚠VERY IMPORTANT MESSAGE⚠
Wittaler [7]

Thank you for this message!

Whoever is reading this, please stay safe from those scammers.

このメッセージをありがとう!

これを読んでいる人は誰でも、それらの詐欺師から安全を守ってください。

이 메시지에 감사드립니다!

이 글을 읽는 사람은 사기꾼들로부터 안전을 유지하십시오.

Quien esté leyendo esto, manténgase a salvo de esos estafadores.

7 0
2 years ago
Read 2 more answers
Heya!!<br><br>•DEFINE DATA SCIENCE??<br>(∩_∩)<br><br>#kavya#<br>​
anastassius [24]

Answer:

Explanation:

Data science defined

Data science encompasses preparing data for analysis, including cleansing, aggregating, and manipulating the data to perform advanced data analysis. Analytic applications and data scientists can then review the results to uncover patterns and enable business leaders to draw informed insights.

5 0
2 years ago
HELP PLSSSSS!!! I WILL MARK BRAINLIEST FOR THE FIRST AND CORRECT ANSWER!!!
dalvyx [7]
The answer you are looking for would be A. Hardware can be an external tool, where as software is an internal tool. Hope this helped!
6 0
3 years ago
Read 2 more answers
What would a match() property that passed the expression /^[0-9]/ check for?
lord [1]

Answer:

E

Explanation:

I took the test

7 0
2 years ago
Read 2 more answers
Other questions:
  • Jameis is researching at his local library when he finds a perfect source to use in his paper. When he goes to check the book ou
    12·2 answers
  • What Event is called when an Object collides with an non-trigger collider?
    13·1 answer
  • All of the following activities may infect your computer with a virus EXCEPT ________.
    6·1 answer
  • What are two examples of ways an electronic record may be distributed to others?
    15·1 answer
  • Write a class called (d) Teacher that has just a main method. The main method should construct a GradeBook for a class with two
    7·1 answer
  • Write a method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(l
    5·1 answer
  • What’s Discord Packing?
    8·2 answers
  • When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustm
    13·1 answer
  • Write a program to input a number.Find the sum of digits and number of digits
    10·2 answers
  • In the computer science industry, the process of finding and removing errors from computer hardware or software is known as
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!