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
Software that communicates with the hardware and allows other programs to run. It is comprised of system software, or the fundam
alukav5142 [94]

Answer:An operating system, or "OS," is software that communicates with the hardware and allows other programs to run. It is comprised of system software, or the fundamental files your computer needs to boot up and function.

Explanation:

8 0
2 years ago
What may happen if a large number of computer users are trying to access a web site at the same time as you ?
Ber [7]
It Will Say " Too Many People At A Time Trying To Get In " And It Will Say Wait .
6 0
3 years ago
What is the name of a statement written to retrieve specific data from a table?
Shkiper50 [21]
The answer is b.record
4 0
3 years ago
Which of the following is a best practice regarding the Administrator account?
lara31 [8.8K]

Answer:

B. The account should be given a nondescript account name that cannot be easily guessed.

3 0
3 years ago
You can separate words in a macro name by using the ____ character
Maru [420]
You can separate words in a macro name by using the underscore character.

A macro is considered as a small reusable computer program. It is efficient as it helps you save time by automating any repeated task.
In order to create a macro, you do not need to be an expert in programming, however, a little knowledge about it will help.

8 0
3 years ago
Read 2 more answers
Other questions:
  • You have to communicate a signal in a language that has 3 symbols A, B and C. The probability of observing A is 50% while that o
    11·1 answer
  • Assume that to_the_power_of is a function that expects two integer parameters and returns the value of the first parameter raise
    13·1 answer
  • A cell reference that has only one $ is referred to as a(n) ____ cell reference. alternative mixed relative absolute
    7·1 answer
  • 4. An outline is most like which of the following? (1 point)
    14·1 answer
  • Can someone help me to give this guy brainliest the button is not there
    8·1 answer
  • A. Write a program that asks the user to enter an integer, then prints a list of all positive integers that divide that number e
    11·1 answer
  • What does a production possibilities curve represent?Which of the following statements are true? Economic stability means fair d
    9·1 answer
  • Python3
    7·1 answer
  • Yuygiihjiujjhuuuuykjyt​
    13·1 answer
  • Tor F: Deleting cell data is the same as clearing the contents of a cell.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!