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 terms best describes the product development life cycle process?
RUDIKE [14]

Answer:

D

Explanation:

Evaluative

3 0
3 years ago
Read 2 more answers
Why would you use a billeted list in a slide presentation?
Damm [24]

Answer:

You would use a Bullet Point on a slide presentation because its concise and to the point.

Explanation:

The correct way to use a Bullet point is to keep it simple. Its not made to be a full sentence. You need to create a bullet point you can expand upon. when you keep it plain and simple you can get more info on your points.

7 0
3 years ago
Florida convicted __________ people of DUI in a one-year period from 2009 to 2010.
natka813 [3]
In 2009 at least 48,516 people were convicted of DUI and in 2010 at least 43,568. Both of the years together adds up to 92,084.

Hope this helps!
3 0
3 years ago
The computer code behind password input can be modified to force people to change their password for security reasons. This is k
bazaltina [42]

Answer:

to remember the passwords you could either make a little rhyme to "help" remember it or you could be like everyone else and write it down on a piece of paper. you could also write the password over and over again to make it stick. a way to make a password different from an old one is to use completely different wording and completely different numbers.

Explanation:

3 0
2 years ago
Implement a Java program that creates math flashcards for elementary grade students. User will enter his/her name, the type (+,
jeka57 [31]

import java.util.Scanner;

public class JavaApplication44 {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.print("Enter you name: ");

       String name = scan.nextLine();

       System.out.print("Enter your operation (+,-,*,/): ");

       String operator = scan.nextLine();

       System.out.print("Enter the range of the problems: ");

       int ran = scan.nextInt();

       System.out.print("Enter number of problems: ");

       int problems = scan.nextInt();

       int score = 0;

       for (int i = 1; i <= ran; i++){

           int first = (int)(Math.random()*ran);

           int sec = (int)(Math.random()*ran);

           System.out.print("Problem #"+i+": "+first + " "+operator+" "+sec+" = ");

           int ans = scan.nextInt();

           if (operator.equals("+")){

               if (ans == first + sec){

                   System.out.println("Correct!");

                   score++;

               }

               else{

                   System.out.println("Wrong. The correct answer is "+(first+sec));

               }

           }

           else if(operator.equals("-")){

               if (ans == first - sec){

                   System.out.println("Correct");

                   score++;

               }

               else{

                   System.out.println("Wrong. The correct answer is "+(first - sec));

               }

           }

           else if (operator.equals("*")){

               if (ans == first * sec){

                   System.out.println("Correct");

                   score++;

               }

               else{

                   System.out.println("Wrong. The correct answer is "+(first * sec));

               }

           }

           else if (operator.equals("/")){

               if (ans == first / sec){

                   System.out.println("Correct");

                   score++;

               }

               else{

                   System.out.println("Wrong. The correct answer is "+(first / sec));

               }

           }

           

       }

       System.out.println(name+", you answered "+score+" questions correctly.");

   }

   

}

I hope this helps!

8 0
3 years ago
Other questions:
  • In a @return tag statement the description:
    13·2 answers
  • __ is/are the amount of blank space between lines of text in a paragraph
    7·2 answers
  • Given an array A of size N, and a number K. Task is to find out if it is possible to partition the array A into K contiguous sub
    9·1 answer
  • Which of the following does not use a Graphic User Interface?
    14·1 answer
  • One of the best ways to shoot a picture is to frame the subject in the middle of the screen or viewer. T or F
    14·2 answers
  • When a new word processing software program is released, companies that might use it must consider not only the cost of buying i
    13·1 answer
  • Since the rules cannot address all circumstances, the Code includes a conceptual framework approach for members to use to evalua
    8·1 answer
  • Describe FIVE distinct features of multi-threaded programming. Your answer should be language independent. g
    9·1 answer
  • What does an arrow after a command indicate
    13·2 answers
  • How do you enlarge an image to see more detail on it? (1 point)
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!