I can't print what I need and I can't figure it out **wall** - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: I can't print what I need and I can't figure it out **wall** (/thread-32791.html) |
I can't print what I need and I can't figure it out **wall** - icedragon978 - Mar-06-2021 This is my code. dasy_of_vaycay = int(input()) budget = float(input()) people = int(input()) gas_from_100 = float(input()) money_to_eat_per_day = float(input()) money_for_rent = float(input()) distance_day1 = int(input()) distance_day2 = int(input()) distance_day3 = int(input()) distance_day4 = int(input()) distance_day5 = int(input()) distance_day6 = int(input()) distance_day7 = int(input()) total_money_for_rent = 0 total_money_to_eat = 0 diff = 0 current_expenses = 0 if people > 10: money_for_rent = money_for_rent * people * 0.75 total_money_for_rent = money_for_rent * 0.25 elif people < 10: total_money_for_rent = money_for_rent * dasy_of_vaycay total_money_to_eat = money_to_eat_per_day * dasy_of_vaycay * people current_expenses = total_money_to_eat + total_money_for_rent for i in range(dasy_of_vaycay + 1): if current_expenses > budget: diff = current_expenses - budget * (-1) print(f'Not enough money to continue the trip. You need {diff}$ more.') break elif gas_from_100: total_gas_day1 = gas_from_100 * distance_day1 total_gas_day2 = gas_from_100 * distance_day2 total_gas_day3 = gas_from_100 * distance_day3 total_gas_day4 = gas_from_100 * distance_day4 total_gas_day5 = gas_from_100 * distance_day5 total_gas_day6 = gas_from_100 * distance_day6 total_gas_day7 = gas_from_100 * distance_day7 total_gas_from_100 = total_gas_day1 + total_gas_day2 + total_gas_day3 + total_gas_day4 + total_gas_day5 /\ + total_gas_day6 + total_gas_day7 current_expenses += total_gas_from_100 if i == 3 or 5: current_expenses = current_expenses * 0.4 elif i == 7: current_expenses = current_expenses / people diff = current_expenses - budget * (-1) print(f'You have reached the destination. You have {diff}$ budget left.') else: print(f'Not enough money to continue the trip. You need {diff}$ more.')This is my task. https://ibb.co/SfXZKWd RE: I can't print what I need and I can't figure it out **wall** - buran - Mar-06-2021 Did you try string formatting? e.g. print(f'You have reached the destination. You have {diff:.2f}$ budget left.')As a side note - you have A LOT of repeating code - you need to better structure your code, use data structures, loops etc. RE: I can't print what I need and I can't figure it out **wall** - deanhystad - Mar-06-2021 You cannot do this: distance_day1 = int(input()) distance_day2 = int(input()) distance_day3 = int(input()) distance_day4 = int(input()) distance_day5 = int(input()) distance_day6 = int(input()) distance_day7 = int(input())There are two things wrong. First, the assignment says travel distance is is a real number, not an integer. More importantly, the number of days is an input, not 7. |