Python, If statements with payroll program - python

Hey guys I have to do this payroll program for my programming class, but I'm about to fry my brain, because I can't get to do some if statements with the conditions my assignment is asking for. Here's what I have to do
Salespeople at SoftwarePirates get paid a base salary of $2000 per month. Beyond the base salary, each salesperson earns commission on
the following scale:
Sales | Commission Rate | Bonus
<10000 | 0% | 0
10000 – $100,000 | 2% | 0
$100,001 - $500,00 | 15% | $1000
$500,001 - $1,000,000 | 28% | $5000
$1,000,000 | 35% | $100,000
The following additional conditions apply:
If a salesperson has taken more than 3 vacation days in a month, their pay gets reduced by $200
A salesperson earns a bonus only if they have been with the company for 3 months or more
For salespeople who have been with the company for more than 5 years and who have made sales greater than $100,000 an additional
bonus of $1000 is added
Here's the code I've had so far(it's pretty messy, but I can only use if statements, not while loop or stuff like that since we are following the class book)
name = input("What's your name? ")
time = int(input("Enter the amount of months you've been working for SoftwarePirates Inc.: "))
vacation = input('Have you taken more than 3 days of vacations(yes or no) ')
sales = float(input("What were your sales this year? "))
def comissionOne():
base = 24000
print("Your commision rate is 0%, so your salary for the year is $", base)
if time <=3:
print("No bonus earned")
if vacation == 'yes':
print ("Your salary is reduced by $200 for taking more than 3 days off, leaving you at $", (base-200))
elif vacation == 'no':
print()
def comissionTwo():
base = 24000
print("Your commision rate is 2%, so your salary for the year is $", (base*0.02 + base))
if time <=3:
print("No bonus earned")
if vacation == 'yes':
print ("Your salary is reduced by $200 for taking more than 3 days off, leaving you at $", (base*0.02 + (base-200)))
elif vacation == 'no':
print()
def comissionThree():
print("Your commision rate is 15%, so your salary for the year is $", (base*0.15 + base))
if time <=3:
print("No bonus earned")
elif time > 3 and < 60:
print("Bonus of $1000 earned")
elif time >= 60:
print("Bonus of $1000 for being in the company for over 5 years")
if vacation =='yes':
print ("Your salary is reduced by $200 for taking more than 3 days off, leaving you at $", (base*0.15 + (base-200)))
elif vacation == 'no':
print()
def main():
print("Hi", name)
if sales < 10000:
comissionOne()
elif sales >=10000 and sales <=100000:
comissionTwo()
elif sales >=100001 and sales <=500000:
comissionThree()
elif sales >=500001 and sales <=1000000:
print("Your commision rate is 28%, so your salary for the year is $", (base*0.28 + base))
elif sales >=1000001:
print("Your commision rate is 35%, so your salary for the year is $", (base*0.35 + base))
main()
Thank you, hope anyone can guide me through this! I just don't know how to apply the conditions to the final gross pay.

You're writing your if conditions with multiple checks wrong. When you need to check multiple conditions, you are doing this:
if foo > 0 and < 60:
# then...
But you should be doing:
if foo > 0 and foo < 60:
# then..
or like this:
if 0 < foo < 60:
# then...

Related

How to get the code to display amount of the discount & the total amount of the purchase after the discount & including the giftwrapping if needed

baseballs cost $1.99 each
Develop a Python program that prompts the user to enter the number of baseballs purchased
In addition the program should ask the user if they want giftwrapping and if so add another $2.00 to the order.
I simply want my output to prompt the amount of the discount
(if any) and the total amount of the purchase after the discount and
including the giftwrapping if needed. But I don't know what code is needed to display that output? so I need someone to show me what code it is?
Quantity Discount
0 - 9 0%
10 - 50 5%
51 or more 10%
baseballs = int(input("Enter the number of baseballs purchased: "))
if(baseballs>0):
if baseballs<=9:
disc = baseballs*0.00
elif baseballs<=50:
disc = baseballs*0.05
elif baseballs>=51:
disc=baseballs*0.10
print("Discount : ",disc)
gift_wrapping = input("Do you want gift wrapping?: ")
print(baseballs + " " + "baseballs purchased" )
print(gift_wrapping)
Something like this maybe? Not 100% sure what you're asking:
Do let me know if you want comments on the code.
price = 1.99
baseballs = int(input("Enter the number of baseballs purchased: "))
if(baseballs>0):
if 0 <= baseballs <= 9:
disc = baseballs*0.00
elif 9 <= baseballs <= 50:
disc = baseballs*0.05
elif baseballs <= 51:
disc=baseballs*0.10
print("Discount : ",disc)
gift_wrapping = input("Do you want gift wrapping?: ")
if gift_wrapping == "yes" or "y" or "Yes":
total = (baseballs * price) - disc + 2
else:
total = (baseballs * price) - disc
print(str(baseballs) + " " + "baseballs purchased" )
if disc != 0:
total_disc = total-(baseballs*price)
print("Discount: "+str(total_disc))
print("Total price "+str(total))

Python shows no error code, but has no output

I am brand new to coding so I hope this is a small mistake. Below is the code for an assignment on a paper carrier's salary. I get no error codes but no output, even the print functions do not show. Please help
# This program will calculate the weekly pay of a paper carrier.
# Developer: Hannah Ploeger Date: 08/30/2022
def main():
# initialize variables
paperCost = 4
commission = 0.05
# prompt user for number of papers
numPaper = eval(input("How many papers are delivered on your route?"))
# prompt user for days of delivery
numDays = eval(input("How many days was the paper delivered this week"))
# prompt user for tips recieved
numTips = input("How much did you recieve in tips this week?")
# calculate salary
weekPay = ((numPaper * numDays) * paperCost) * commission
totalPay = weekPay + numTips
# display output
print("This week you delivered", numPaper, "papers")
print("Your salary this week is $", weekPay)
print("Your total tips were $", numTips)
print("Your total pay is $", totalPay)
enter image description here
add this:
if __name__ == "__main__":
main()
just call the main function
def main():
# initialize variables
paperCost = 4
commission = 0.05
# prompt user for number of papers
numPaper = eval(input("How many papers are delivered on your route?"))
# prompt user for days of delivery
numDays = eval(input("How many days was the paper delivered this week"))
# prompt user for tips recieved
numTips = input("How much did you recieve in tips this week?")
# calculate salary
weekPay = ((numPaper * numDays) * paperCost) * commission
totalPay = weekPay + numTips
# display output
print("This week you delivered", numPaper, "papers")
print("Your salary this week is $", weekPay)
print("Your total tips were $", numTips)
print("Your total pay is $", totalPay)
main() # calling main function

Python Shipping Calculator Using IF Statements

I am trying to make a Shipping calculator in python by using IF Statements.
The application should calculate the total cost of an order including shipping. I am stuck at a point where python just won't run my code at all. I have a feeling I'm close but I do not know what is wrong with what I'm inputting because python won't return any errors. please someone just steer me in the right direction.
Instructions:
Create a program that calculates the total cost of an order including shipping.
When your program is run it should ...
Print the name of the program "Shipping Calculator"
Prompt the user to type in the Cost of Items Ordered
If the user enters a number that’s less than zero, display an error message and give the user a chance to enter the number again.
(note: if you know loops/iterations, OK to use here, but if not, just a simple one-time check with an if statement will be OK here.)
For example: if the cost is less than zero, print an error message and then re-ask once for the input.
Use the following table to calculate shipping cost:
Cost of Items
Shipping cost
<30
5.95
30.00-49.99
7.95
50.00-74.99
9.95
>75.00
FREE
Print the Shipping cost and Total Cost to ship the item
End the program with an exit greeting of your choice (e.g. Thank you for using our shipping calculator!)
Example 1:
=================
Shipping Calculator
=================
Cost of items ordered: 49.99
Shipping cost: 7.95
Total cost: 57.94
Thank you for using our shipping calculator!
Example 2:
=================
Shipping Calculator
=================
Cost of items ordered: -65.50
You must enter a positive number. Please try again.
Cost of items ordered: 65.50
Shipping cost: 9.95
Total cost: 75.45
Thank you for using our shipping calculator!
Here is the code I have written out so far:
#Assignment shipping calculator
#Author: Name
def main():
print("Shipping Calculator")
subtotal = calc_subtotal()
shipping = calc_shipping()
total = calc_total()
main()
def calc_subtotal():
subtotal = float(input("Cost of Items Ordered: $"))
if subtotal <= 0:
print("You must enter a positive number. Please try again.")
return subtotal
def calc_shipping():
subtotal = calc_subtotal()
shipping = calc_shipping
if subtotal >= 1 and subtotal <= 29.99:
shipping = 5.95
print("Shipping Cost: $5.95")
if subtotal >= 30 and subtotal <= 49.99:
shipping = 7.95
print("Shipping Cost: $7.95")
if subtotal >= 50 and subtotal <= 74.99:
shipping = 9.95
print("Shipping Cost: $9.95")
if subtotal >= 75:
shipping = 0
print("Shipping Cost: Free")
def calc_total():
total = calc_subtotal() + calc_shipping()
print("Total Cost: ",total)
print("Thank you for using our shipping calculator!")
First, I will put the code here then explain all the changes I made (your original attempt was very close, just a few tweaks):
#Assignment shipping calculator
#Author: Name
def main():
print("Shipping Calculator")
subtotal = calc_subtotal()
shipping = calc_shipping(subtotal)
calc_total(subtotal,shipping)
def calc_subtotal():
subtotal = float(input("Cost of Items Ordered: $"))
while subtotal <= 0:
print("You must enter a positive number. Please try again.")
subtotal = float(input("Cost of Items Ordered: $"))
return subtotal
def calc_shipping(subtotal):
if subtotal >= 1 and subtotal <= 29.99:
shipping = 5.95
print("Shipping Cost: $5.95")
if subtotal >= 30 and subtotal <= 49.99:
shipping = 7.95
print("Shipping Cost: $7.95")
if subtotal >= 50 and subtotal <= 74.99:
shipping = 9.95
print("Shipping Cost: $9.95")
if subtotal >= 75:
shipping = 0
print("Shipping Cost: Free")
return shipping
def calc_total(subtotal,shipping):
total = subtotal + shipping
print("Total Cost: $" + str(round(total,2)))
print("Thank you for using our shipping calculator!")
main()
As #Devang Sanghani mentioned, you should call your main() outside of your function so that it will run
For your calc_subtotal() function, use a while loop to keep taking in user input until given a valid number. Make sure you move your return subtotal outside of this loop so that it will only return it once this number is valid.
In your calc_shipping() function, make sure you take in subtotal as a parameter since you are using it in your function. Make sure you also return shipping.
Similarly, in your calc_total() function, take in both subtotal and shipping as parameters since they are used in your function.
Given these changes, update your main() function accordingly.
I hope these changes made sense! Please let me know if you need any further help or clarification :)
Adding to the above answers, also consider the case where the price can be a few cents, so this line should change:
if subtotal >= 0 and subtotal <= 29.99: # changed from 1 to 0
So there seem to be 2 errors:
You forgot to call the main function
You indented the return statement in calc_subtotal() so it returns the value only if the subtotal <= 0
The correct code might be:
def main():
print("Shipping Calculator")
subtotal = calc_subtotal()
shipping = calc_shipping()
total = calc_total()
def calc_subtotal():
subtotal = float(input("Cost of Items Ordered: $"))
if subtotal <= 0:
print("You must enter a positive number. Please try again.")
calc_subtotal() # Re asking for the input in case of invalid input
else:
return subtotal # returning subtotal in case of valid input
def calc_shipping():
subtotal = calc_subtotal()
shipping = calc_shipping
if subtotal >= 0 and subtotal <= 29.99:
shipping = 5.95
print("Shipping Cost: $5.95")
if subtotal >= 30 and subtotal <= 49.99:
shipping = 7.95
print("Shipping Cost: $7.95")
if subtotal >= 50 and subtotal <= 74.99:
shipping = 9.95
print("Shipping Cost: $9.95")
if subtotal >= 75:
shipping = 0
print("Shipping Cost: Free")
def calc_total():
total = calc_subtotal() + calc_shipping()
print("Total Cost: ",total)
print("Thank you for using our shipping calculator!")
main() # Calling main

Loop function for a check out program in python

My teacher wants this code to run on a loop but I am not sure how to do that. Can anyone help me please?
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
if ask == "potatoes":
def potatoes (quantity, price=5.99):
total = quantity * price
while True:
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
return (0.879 * total) + total
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
potatoes(int(input("Enter the quantity of Potatoes you bought : ")), 8.99)
Your code is very wrong and it will not run, but I have an idea of what you are trying to do, so this will work
def potatoes (quantity, price=5.99):
total = quantity * price
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
tax3 = (0.879 * total) + total
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
while True:
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
if ask == "potatoes":
number_of_potatoes = int(input("Enter the quantity of Potatoes you bought : "))
potatoes(number_of_potatoes, 8.99)
else:
print('Thank you visiting')
break
Your code is a little bit confusing but i hope this is what you intended for.
1.I moved the function definition out of the loop, and it is inside the loop that you call it so the code inside the function can be reused as many times as you need!
2.I also changed the loop condition for when the user inserts "no" so there's an end to it, but change for whatever you want
3.About the return statement it's important to remember that when it's executed the function that it is within ends and return the designated value, everything after it won't be executed, that's why i moved it to the end.
4.And finally there's a variable tax3 that isn't being defined anywhere in your code, maybe you didn't put it here or maybe you just forgot about it, so you need to fix it or delete it so the code works. Hope i understood your question, good programming!
def potatoes (quantity, price=5.99):
total = quantity * price
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
return (0.879 * total) + total
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
while(ask != "no"):
if ask == "potatoes":
potatoes(int(input("Enter the quantity of Potatoes you bought : ")), 8.99)
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")

Admission Price based on age and coupons

Im attempting to write a code where the user if prompted for todays date and their birthdate in order to determine their age. The age will determine how much their ticket price will be. If they are 14 and younger the price would be five dollars. If they are 15 to 64 the price would be nine dollars and if they are 65 and older the price would be 7.50. It would ask if the customer has a coupon, which would take off one dollar off their price. What I have so far:
print ("Hello, welcome to Hopper's Computer Museum! To determine your enterance fee, please enter the following:")
print ('Your Date of Birth (mm dd yyyy)')
Date_of_Birth = input("--->")
print ('Todays Date: (mm dd yyyy)')
Todays_Date = input("--->")
age = (tYear-bYear)
if (bMonth > tMonth):
age == age-1
if (bMonth == tMonth and
bDay > tDay):
age == age-1
if age < 14:
price==5.00
elif age > 15 and age < 64:
price==9.00
elif age > 65:
price==7.50
print ('Do you have a coupon (y/n)?')
Discount = input("--->")
if Discount == "y" or Discount == "Y":
price = price-1
elif Discount == "n" or Discount == "N":
price = price
print ('Your admission fee is $4.00 enjoy your visit!')
I know that I need define my variables such as tYear, bYear, bDay, ect, but I'm not sure what I should assign them to.
You can use map to assign values to tYear, bYear etc. You can do following instead of Date_of_birth = input('--->')
bDay,bMonth,bYear = map(int,raw_input('--->').split())
This will assign bDay, bMonth and bYear as per requirement if the input format is 'dd mm yyyy'. Similarly for today's date you can write:
tDay,tMonth,tYear = map(int,raw_input('--->').split())
Alternate option is to calculate age using datetime. Follow this - Age from birthdate in python

Categories