Can you please show me the fault? | Sololearn: Learn to code for FREE!


Can you please show me the fault?

#Lab 03: Functions, Modules and I/O #Exercise 01 #1.1 def surface_eval(x,y): import math a=math.sin(x) b=math.cos(y) z=(a ** 2)*b return z file1 = open('dataset1.txt','r') file2 = open("out.txt",'a') for line in file1: inp=list(line.split(',')) x = float(inp[0]) y = float(inp[1]) z = surface_eval(x,y) print('x: ','%.4f'%x,'y: ','%.4f'%y,'z: ','%.4f'%z) file2 .write(str(z)+'\n') file2.close() file1.close()

8/7/2021 5:22:18 AM

Ushani Harshila

3 Answers

New Answer


Ushani Harshila , ▪︎if the input file 'dataset1.txt' is existing in the correct folder (same as where code file is located), the program will create no error. i can not say if your calculation is correct, this is up to you to check. ▪︎if you run the code multiple times, the output will be appended to the output file 'out.txt'. this means that the file content is increasing (repeated) with each code ecexecution this is the result: x: 10.0000 y: 3.0000 z: -0.2930 x: 7.0000 y: 6.0000 z: 0.4144 x: 9.0000 y: 4.0000 z: -0.1110


Ushani Harshila , if you really have a problem, we need some more details from you: ▪︎give a clear and complete description about your task ▪︎if there are error messages please post them here ▪︎give at least one sample with input data (content of the 2 files) and the expected output thanks for your understanding!


Provide a codebit to test and a requirements