Skip to content
Advertisement

Why is my round function not working when I have a float in Python? I tried many methods online, but none work [closed]

I was working on a project where I could find out a users balance with a monthly payment, interest and term of the payment. But when I look through the code my round function shows an error. I looked online and found different methods like formatting and such but none seemed to work. It all seems correct, I asked a few classmates and they can’t figure out the problem either. Help is appreciated. If you want me to specify more you can comment and I can get to it as soon as possible.

Link for the file used in the program: https://vsbworld-my.sharepoint.com/:x:/g/personal/1253540_learn_vsb_bc_ca/ESbQS3z58CdBspGmKN74IDABH-mlT7B7tN_ZFuFtq77fpQ?e=f15c8c

JavaScript

Advertisement

Answer

Here is a version of your code that works. Your CSV file has quoted fields with embedded commas, so your “split” was not sufficient. I’ve changed this to use the csv module, since it can handle quoting. I’ve also converted the MSRP column to float right away.

Your interest/payment computation was wrong. I’ve fixed that. It seems kind of silly to ask “do you want to buy a car”, since they would not have run the program if they didn’t.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement