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
Suppose that a company offers quantity discounts. If up to​ 1,000 units are​ purchased, the unit price is ​$1010​; if more than​
zhenek [66]

Answer:

Ans. Ready to download, please see the file attached to this document

Explanation:

Note. Consider changing the cell in yellow, does not make sense, it could be 10100 instead of 1010

Hi, to design this sheet, I also used the and(...) function of MS excel, in which you declate that in order to select a certain answer, 2 or more conditions must be true, in our case, if a purchase is up to 1000, the price would be $1010 (consider changing this value, maybe to 10100), if the purchase is more than 1000 and less than 5000, the price is $9,509.50, and if is more than 5000 units, the price would be $5,5005.50.

Please check the formula for further clarifications.

Best of luck.

Download xlsx
7 0
3 years ago
What color model should Joe use if he will be using an offset printing press?
EleoNora [17]

Answer:

CMYK

Explanation:

Monitors typically use RGB color (additive model — adding to make white), but offset printing uses CMYK pigments (subtractive color — subtracting from the existing white). Printed images have less visual range, saturation, and contrast than digital images, so in print, colors will usually appear darker and less vibrant.

6 0
3 years ago
How do you create a function in C++
MArishka [77]

Answer:

1. Declaration: the return type, the name of the function, and parameters (if     any)

2. Definition: the body of the function (code to be executed)

Explanation:

7 0
1 year ago
Which of the following are characteristics of a cell
olganol [36]

Answer:

-occurs at the intersection of columns and  rows

-is a single unit for entering data on a  spreadsheet

-is located according to its cell reference or  cell address

Explanation:

A cell is a box in a spreadsheet program that contains information and each cell is identified using a cell reference that indicates the colum letter followed by the row number where the cell is located. So, according to this, the characteristics of a cell in a spreadsheet software are:

-occurs at the intersection of columns and  rows

-is a single unit for entering data on a  spreadsheet

-is located according to its cell reference or  cell address

5 0
3 years ago
Professor Gig A. Byte needs to store text made up of the characters A with frequency 6, B with frequency 2, C with frequency 3,
Luden [163]

Answer:

This is not true

Explanation:

The optimal Huffman code is used to encrypt and compress text files. It uses fixed-length code or variable-length code for encryption and compression of data.

The professor's character code is similar to Huffman's variable-length coding which uses variable length od binary digits to represent the word strings. The file size of the text file above is;

= 6 x 1 + 2 x 2 + 3 x 2 + 2 x 2 + 8 x 1 = 28 bits

This would be the same for both cases.

The encrypt would be the problem as the encoded and decoding of the characters B and E may cause an error.

8 0
2 years ago
Other questions:
  • What are words with the root gest?
    15·1 answer
  • Conduct online research and provide some guidelines on how to secure a web browser. (CyberSecurity plato)
    10·1 answer
  • To create a chart, you need to select at least
    8·1 answer
  • Aubrey uses the following formula to calculate a required value. Which elements of the formula use mixed cell referencing?
    13·2 answers
  • Which one my guys I need help
    7·1 answer
  • If you misspell a word in your Java program it may be true that I. the program will not compile II. the program may compile, but
    6·1 answer
  • Cyberbullying can negatively impact a victim’s <br> well-being.
    13·1 answer
  • Briefly describe the traditional definition of the digital divide. What is it and who is affected, positively and adversely? How
    15·1 answer
  • What are node in a computer network​
    14·1 answer
  • Who has more Tanks? Russia or USA? You get ti right and you get BRAINLIEST
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!