Question: Complete the code so it will read strings from a file and convert them to numbers. Replace 'FillThisIn' with missing code. # Expected output: #

Complete the code so it will read strings from a file and convert them to numbers. Replace 'FillThisIn' with missing code.
# Expected output:
# String '4' converted to number: 4.00
# String '4.5' converted to number: 4.50
# String 'ten' cannot be converted to number
# String '4,000' cannot be converted to number
FillThisIn:
file8= open('DataFile8.txt','r')
FillThisIn:
print("Error: File not found")
exit()
for line in file8:
line = line.rstrip('
')
print(f"String '{line}'", end="")
FillThisIn:
num = float(line)
print(f"converted to number: {num:.2f}")
FillThisIn:
print("cannot be converted to number")
file8.close()
 Complete the code so it will read strings from a file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!