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
Rudiy27
3 years ago
11

Two files named numbers1.txt and numbers2.txt both have an unknown number of lines, each line consisting of a single positive in

teger. Write some code that reads a line from one file and then a line from the other file. The two integers are multiplied together and their product is added to a variable called scalar_product which should be initialized to zero. Your code should stop when it detects end of file in either file that it is reading. For example, if the sequence of integers in one file was "9 7 5 18 13 2 22 16" and "4 7 8 2" in the other file, your code would compute: 4*9 + 7*7 + 8*5 + 2*18 and thus store 161 into scalar_product.
Computers and Technology
1 answer:
Reika [66]3 years ago
6 0

Answer:

see explaination for program code

Explanation:

scalar_product = 0

li=[]

li2=[]

#reading numbers1.txt and numbers2.txt intoli and li2 respectively

with open('numbers1.txt') as n1, open('numbers2.txt') as n2:

for line1 in n1:

li.append(int(line1))

for line2 in n2:

li2.append(int(line2))

#storing min list size into variable l

a=len(li)

b=len(li2)

if a<b:

l=a

else:

l=b

#calculating scalar product

for i in range(l):

scalar_product=scalar_product+li[i]*li2[i]

print("scalar product is",scalar_product)

You might be interested in
Think of some local businesses that have websites. Look online and identify two different websites for businesses or services in
GenaCL600 [577]

Explanation:

Professional service-based businesses are well suited for the Internet, because the primary services they provide are information-based. A housecleaning or lawn care service business is not suited well for the Internet because the delivery of those services requires the provider to be physically present.

7 0
2 years ago
You can use pen and highlighter tools to emphasize information on a slide during a PowerPoint presentation. These tools are avai
Savatey [412]
ANSWER:
C. Slide Show toolbar
5 0
3 years ago
Why are computer simulations useful in studying phenomena in the universe?
amid [387]

Answer:

Explanation:

Computer simulations are helpful because they can handle the computation of a big number of variables, at the same time. The universe is a constantly changing place with many different variables changing other variables. Thus, a computer is ideal to simulate, or predict, real life phenomena because of its processing power.

7 0
2 years ago
Another name for a computer's operating system
nadya68 [22]

Answer:

core engine or system software.

Explanation:

just because

5 0
3 years ago
Read 2 more answers
Which of the following is true about occupations within the STEM fields? Many occupations use mathematics, even if it is not the
Kazeer [188]

Answer:

Many occupations use mathematics, even if it is not the primary focus of a given job.

Explanation:

Think about software developers, they develop apps, websites, and other things, but they also use math in the process. Scientists use statistics. Mechanics use math to make sure their measurements are right. Therefore, I think your best bet would be

A. Many occupations use mathematics, even if it not the primary focus of a given job.

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which program or security application prevents access between a private and trusted network, and other untrusted networks?
    8·2 answers
  • Which of the following patterns of cell phone use can be observed in this chart
    12·1 answer
  • Emilio is reviewing the data he collected from historical records about immigration in the united states. He decides to create a
    5·1 answer
  • Which of the following information should be included in audit documentation? a. Procedures performed. b. Audit evidence examine
    13·1 answer
  • Adobe reader is a type of​
    14·2 answers
  • The physical part or components of a computer system called​
    5·2 answers
  • Which type of appliance can host several functions, such as antimalware, firewall, content filter, and proxy server
    11·1 answer
  • Exercise 3.6.9: 24 vs. "24"5 points
    7·1 answer
  • Interstate highway numbers Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 of 95) go north/south, an
    8·1 answer
  • _____ is a system in which a finite set of words can be combined to generate an infinite number of sentences.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!