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
Please sign this!! https://www.change.org/ban-charli-damelio
pav-90 [236]

Answer:

Idc

Explanation:

5 0
3 years ago
Read 2 more answers
The ___________ method returns the length of an array.
MaRussiya [10]

Answer:

A. Append

Explanation:

4 0
2 years ago
Read 2 more answers
When testing a game, why might you consider throttling the game’s “frames per second”?
Ivenika [448]

Answer:

because if you throttle it then

you can make sure it's okay

4 0
2 years ago
How do you run a function in python?
Black_prince [1.1K]
You can call a Python function like so: function(parameters).

Example:

Define function add:
def add(x,y):
return x+y

Call function:
add(3,7) -> 10
3 0
3 years ago
In the blank LibreOffice Writer document, to start the process of entering a date field into a letter, click on the Insert menu.
trasher [3.6K]

what is the question? it just seems like directions

5 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is NOT a web browser?<br> Safari<br> Chrome<br> Bing<br> Firefox
    8·2 answers
  • What were the goals of the “paperless society” ideal?
    14·2 answers
  • 1.6 code practice: question 1 edhesive
    12·2 answers
  • How can forms help us reduce data-entry errors?
    12·1 answer
  • Which of the following lists the proper order of the categories of the SOC system from general to specific?
    11·1 answer
  • The technology dealing with robots is called
    6·1 answer
  • Which of the following statements is FALSE?
    5·1 answer
  • In attempts to improve their contribution to the environment a company decides to adapt green computing. Which of these techniqu
    13·1 answer
  • A good information that contains the facts necessary for decision makers to solve a problem is characterized by the __________.
    15·2 answers
  • 1. If an android phone is out of date or outdated and it requires an update. Explain the steps how I can update this phone.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!