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
lapo4ka [179]
3 years ago
9

"A file named numbers.txt contains an unknown number of lines, each consisting of a single integer. Write some code that compute

s the sum of all these integers, and stores this sum in a variable name sum."
Computers and Technology
1 answer:
satela [25.4K]3 years ago
7 0

Answer:

Following are the program in the Python Programming Language.

#declare variable and initialize to 0

sum = 0

#read the following file

file = open('numbers.txt', 'r')

#set the for loop

for n in file:

  #convert the file string into the integer and perform sum.

  sum += int(n)

Explanation:

<u>The following are the description of the program</u>.

  • Firstly, declare variable 'sum' and initialize the integer type value i.e., 0.
  • Set the variable 'file' that only read the following file text i.e., 'numbers.txt'.
  • Set the for loop that read the content of the file and store in the variable 'n' one by one.
  • Finally, er convert the following string in to the integer and perform the addition.
You might be interested in
Debug the code in the main method of this class, which is intended to initialize an array named arr to hold 3 ints, fill this wi
pentagon [3]

Answer:

import java.util.Scanner;

public class U6_L1_Activity_One{

 public static void main(String[] args){

   Scanner scan = new Scanner(System.in);

   int[] arr = new int[4];

   arr[1] = scan.nextInt();

   arr[2] = scan.nextInt();

   arr[3] = scan.nextInt();

   System.out.println("Contents: " + arr[1] + " " + arr[2] + " " + arr[3]);

   int Sum = (1 + 2 + 3);

   System.out.println("Sum: " + Sum);

 }

}

Explanation:

5 0
3 years ago
Task1: #Define a function called show_students which takes 2 parameters students and message #Print out a message, and then the
k0ka [10]

Answer:

  1. def show_students(message, sList):
  2.    print(message)
  3.    print(sList)
  4.    print("Our students are currently in alphabetical order")
  5.    sList.sort()
  6.    output = ""
  7.    for student in sList:
  8.        output += "-" + student
  9.    print(output)
  10.    print("Our students are currently in reverse alphabetical order")
  11.    sList.sort(reverse=True)
  12.    output = ""
  13.    for student in sList:
  14.        output += "-" + student
  15.    print(output)  
  16. show_students("Welcome to new semester!", ["Aaron","Bernice", "Cody"])

Explanation:

Firstly we declare a function that will take two inputs, message and student list (Line 1).

In the function, we first print the message and the original input student list (Line 2 - 3). Next, we use sort method to sort the input list and then output the sorted items from the list using a for loop (Line 5-10).

Next, we sort the list again by setting reverse = True and this will sort the list in descending order (Line 13). Again we use the similar way mentioned above to output the sorted items (in descending order) using a for loop (Line 14 -17)

We test the function using a sample student list (Line 18) and we shall get the output:

Welcome to new semester!

['Aaron', 'Bernice', 'Cody']

Our students are currently in alphabetical order

-Aaron-Bernice-Cody

Our students are currently in reverse alphabetical order

-Cody-Bernice-Aaron

6 0
3 years ago
How can people make sure they are using credit cards responsibly
Ray Of Light [21]
Set a buget based on monthly income
8 0
3 years ago
Read 2 more answers
"A queue automaton is like a push-down automaton except that the stack is replaced by a queue. A queue is a tape allowing symbol
Yanka [14]

It is possible in this example to show that a language can be recognized by a deterministic queue automaton if the language is Turing-recognizable.

For computation, we first need to transfer the input string on queue. We do so by using right moves and pushing each read symbol. Then, we simulate the right move of TM with pull of the rightmost elements of the queue and pushing the new symbol according to transition function back to queue. On the other hand, the left reset of TM is simulated using pushing until we reach special symbol which denotes the left-hand end of tape. We push and pull until we are at the right position. Therefore, we can intuitively simulate left-reset Turing machines.

7 0
3 years ago
Do software engineers save millions of dollars in usa
SCORPION-xisa [38]
Yes. They make a lot of money. So eventually after saving your Money, you will make a least 1 million dollars or more.
4 0
3 years ago
Other questions:
  • Nancy finds it difficult to locate emails in her Inbox. What action should she take to locate a particular type of email instant
    11·2 answers
  • A(n) ________ network is a computer network that spans a relatively small area, allowing all computer users to connect with each
    14·1 answer
  • The c++ operator _______________ is used to destroy dynamic variables.
    5·1 answer
  • As a trainer for Exempla Healthcare, Tina is faced with many challenges to properly training her new hires. There are over 40 di
    15·1 answer
  • [Submit on zyLabs] Please write a function with one input, a matrix, and one output, a matrix of the same size. The output matri
    10·1 answer
  • What is the acronym that helps you remember the order of math operations?
    9·2 answers
  • While designing your network's VLAN topology, your team has decided to use a centrally managed DHCP server rather than creating
    8·1 answer
  • This type of connector is the most common for connecting peripherals (printers, monitors, storage devices, etc.) to a windows co
    10·1 answer
  • C++ please
    8·1 answer
  • an early type of GUI is created, which includes windows, pop-ups, icons, and menus. What year did this happen? Please help!!! qu
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!