Python Forum
I can't print what I need and I can't figure it out **wall**
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't print what I need and I can't figure it out **wall**
#1
Sad 
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
buran write Mar-06-2021, 11:14 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
buran likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020