Computer Science, asked by harshverma729, 1 month ago

write a python program that takes two files of equal size as a input from user. The first file containing weight of items and the second file contains corresponding prices . Create another file that should contain price per unit weight for each item​

Answers

Answered by ranugupta418pbm197
0

Answer:

(hy)²=(Base)²+(Chutiyàa)²

is called a pythagorus chutiyà lol XD

Answered by harshsharma1172002
0

Answer:

Explanation:

import sys

def func1(file1,file2,file3):

   '''Objective: Takes two files of equal size as input from the user. The first

   file contains weights of itmes and the second file contains corresponding

   prices.create the another file that should contain price per unit weight for each Item.

   '''

   try:

       fIn1 = open(file1,'r')

       fIn2 = open(file2,'r')

       fOut = open(file3,'w')

   except IOError:

       print("Problem to read and write file");sys.exit()

   lines1 = fIn1.readlines()

   lines2 = fIn2.readlines()

   # Check If files are equal size

   try:

       len(lines1) != len(lines2)

   except IOError:

       print("Files Size are not Equal");sys.exit()

   for i in range(len(lines1)):

       weight = float(lines1[i].strip())

       price = float(lines2[i].strip())

       price_per_unit = price/weight

       fOut.write(str(price_per_unit)+'\n')

   print("Price Per Unit weight calculated succesfully and written to",fOut)

file1 = input("Enter the weight file name: ")

file2 = input("Enter the price file name: ")

file3 = input("Enter the per unit price: ")

calculate = func1(file1,file2,file3)

print(calculate)

Similar questions