0
Decimal places
How do I get my code to drop everything except for the first two decimal places on a calculation? Code below: #SHORT TERM CALCULATOR rate_of_pay = (input("what is the partners rate of pay?
quot;)) #SALARY CALCULATIONS 100% 5 DAY WORK WEEK salary_weekly = float(rate_of_pay)*40 salary_daily = salary_weekly/5 #HOURLY CALCULATION 66.67% 7 DAY WORK WEEK hourly_cal = float(rate_of_pay)*40 hourly_weekly = hourly_cal*.6667 hourly_daily = hourly_weekly/7 #SALARIED TOTALS print ("Salaried WEEKLY = quot; + str(salary_weekly)) print ("Salaried DAILY = quot; + str(salary_daily)) #HOURLY TOTALS print ("Hourly WEEKLY = quot; + str(hourly_weekly)) print ("Hourly DAILY = quot; + str(hourly_daily))6 Antworten
+ 3
Carlee, i checked the code on pc and SoloLearn and it runs without creating an error. You can check your latest version here:
https://code.sololearn.com/cRFDUYzhTAGi/?ref=app Make sure you input 2 lines of data when you are prompted to do so. First line is a value and second line is Y or N.
But i found an other issue that matters. If you input in second line Y (upper) it will return a different result as if you input y (lower).
this is the code that evaluates the input:
if partnershare_factor == 'Y':
print("\n")
print(f'Weekly = $ {salary_weekly:>7.2f}')
print(f'Daily = $ {salary_daily:>7.2f}')
else:
print("\n")
print(f'Weekly = $ {hourly_weekly:>7.2f}')
print(f'Daily = ${hourly_daily:>7.2f}')
It checks for an upper Y. If you input a lower y the else part of the statement will be executed and gives a different result as expected. You can fix this if you make a small amendment:
Instead of: if partnershare_factor == 'Y': use if partnershare_factor.upper() == 'Y':
In this case the input will by converted to uppercase and compared with the uppercase Y.
+ 3
you can use this instead of your current print statements
print(f'Hourly WEEKLY = $ {hourly_weekly:.2f}')
print(f'Hourly WEEKLY = $ {hourly_daily:.2f}')
result is:
Hourly WEEKLY = $ 293.35
Hourly WEEKLY = $ 41.91
print(f'Hourly WEEKLY = $ {hourly_weekly:>7.2f}')
print(f'Hourly WEEKLY = $ {hourly_daily:>7.2f}')
# this does adjust your numbers to the right:
Hourly WEEKLY = $ 293.35
Hourly WEEKLY = $ 41.91
you can teat your code here:
https://code.sololearn.com/c0NHzzoW0i5Y/?ref=app
+ 1
im not sure how to add that to my print output I already have? I keep breaking things when I try :(
0
Lothar
Why am I only able to output that line in thr solo atmosphere? Any other playgrounds I run it through to test error out syntax error...😭😭
0
Jay Matthews line 18
#SHORT TERM CALCULATOR
rate_of_pay = (input("What is the partners rate of pay? quot;))
partnershare_factor = input("Is Partner eligible for PartnerShare? Y/N")
#SALARY CALCULATIONS 100% 5 DAY WORK WEEK
salary_weekly = float(rate_of_pay)*40
salary_daily = salary_weekly/5
#HOURLY CALCULATION 66.67% 7 DAY WORK WEEK
hourly_cal = float(rate_of_pay)*40
hourly_weekly = hourly_cal*.6667
hourly_daily = hourly_weekly/7
if partnershare_factor == 'Y':
print("\n")
print(f'Weekly = $ {salary_weekly:>7.2f}')
print(f'Daily = $ {salary_daily:>7.2f}')
else:
print("\n")
print(f'Weekly = $ {hourly_weekly:>7.2f}')
print(f'Daily = ${hourly_daily:>7.2f}')
0
Lothar yesssss Thank you!!!!!!