I created a program that keeps popping up with an error message that says
Traceback (most recent call last):
File "/Users/salvas/Downloads/Salvas6/program6_2.py", line 23, in <module>
main()
File "/Users/salvas/Downloads/Salvas6/program6_2.py", line 12, in main
reg_price = float(prices_file.readline())
ValueError: could not convert string to float: ''
The program is supposed to use information from a file and display it in a table. I was able to get it to print the information correctly, however, now it comes up with this error. The data includes a destination, the regular price of traveling to this destination, and the discounted percentage which gets calculated into a discounted price in this program. This is the data that I imported from a .txt file that was created using a different program:
San Francisco
550
10
New Orleans
330
10
Atlanta
295
20
def main():
prices_file = open('prices.txt', 'r')
destination = prices_file.readline()
column1 = 'DESTINATION'
column2 = 'REG.PRICE'
column3 = 'REDUCED'
column4 = 'SALE PRICE'
print(f'{column1:<}\t{column2:}\t{column3:}\t\t{column4:}')
while destination != '':
reg_price = float(prices_file.readline())
reduc_percent = float(prices_file.readline())
percentage = reduc_percent / 100
reduced = percentage * reg_price
sale_price = reg_price - reduced
destination = destination.rstrip('\n')
print(f'{destination:<}\t${reg_price:.2f}\t\t${reduced:.2f}\t\t${sale_price:.2f}')
destination = prices_file.readline()
prices_file.close()
if __name__ == '__main__':
main()
This is the program that I created that keeps coming up with an error message.