I'm trying to make an ATM-like program in Python. The idea is that the user inputs any amount of money and the minimum amount of bills (100, 50, 25, 10, 5) will be printed.
So for example:
Input: 258
expected output: "2 $100 Bills, 1 $50 Bill, 1 $5 Bill, 3 $1 Bills".
The program works for number that are multiples of 5, but I can't seem to get the $10 and $1 Dollar bills to behave the same way. Here is the code:
print("Hi! Welcome to Python Bank. \nHow much would you like to withdraw?")
amnt = int(input("Please input amount: "))
if amnt >= 100:
if amnt // 100 >= 2:
print(amnt // 100, "$100 Bills")
else:
print("1 $100 Bill")
if (amnt // 50) % 2 != 0:
print("1 $50 Bill")
if (amnt // 25) % 2 != 0:
print("1 $25 Bill")
if (amnt // 10) % 2 != 0:
print(amnt // 10, "$10 Bills")
if (amnt // 5) % 2 != 0 and (amnt // 25) % 2 == 0:
print("1 $5 Bill")
if (amnt // 1) % 2 != 1:
print((amnt // 1), "$1 Bills")
I'm using the (//) operator since it tells you how many of the number on the right is in the number on the left. Then used the (%) operator with (!= 0). This seems to work for 100, 50, 25, but not for 10 and 1. How can I tackle this?
Your logic is wrong. This is the correct way.
if amount >= 100:
print(amount // 100, '100$ notes')
amount = amount % 100
if amount >= 50:
print('1 50$ notes')
amount = amount % 50
And so on
a cleaner solution would be to use a function to do that for you, just in case you decided to change the coin values.
print("Hi! Welcome to Python Bank. \nHow much would you like to withdraw?")
amnt = int(input("Please input amount: "))
def solve(m):
bills = [100, 50, 25, 10, 5, 1]
dic = {}
for bill in bills:
if m >= bill:
dic[bill] = m // bill
m -= dic[bill] * bill
return dic
def disp(dic):
s = ', '.join([ "{} ${} bills".format(dic[bill], bill) for bill in dic])
print(s)
disp(solve(amnt))
Assuming you have Python3, you can use f-strings, and you can always use a loop for things like these. That way, the logic is consistent for each bill size:
def print_change(amnt, bill_sizes=(100, 50, 25, 10, 5, 1)):
# loop over bill sizes
for bill_size in bill_sizes:
# skip if there isn't enough left for this bill
if amnt >= bill_size:
# remove n number of bills from amnt
n = amnt // bill_size
amnt -= n * bill_size
# print the results, with an 's' if there are more than one
print(f'{n} ${bill_size} Bill' + ('s' if n > 1 else ''))
print("Hi! Welcome to Python Bank. \nHow much would you like to withdraw?")
print_change(int(input("Please input amount: ")))
I simply just added an elif to check if they inputted 1 and it seems to do what I think you want.
print("Hi! Welcome to Python Bank. \nHow much would you like to withdraw?")
amnt = int(input("Please input amount: "))
if amnt >= 100:
if amnt // 100 >= 2:
print(amnt // 100, "$100 Bills")
else:
print("1 $100 Bill")
if (amnt // 50) % 2 != 0:
print("1 $50 Bill")
if (amnt // 25) % 2 != 0:
print("1 $25 Bill")
if (amnt // 10) % 2 != 0:
print(amnt // 10, "$10 Bills")
if (amnt // 5) % 2 != 0 and (amnt // 25) % 2 == 0:
print("1 $5 Bill")
if (amnt // 1) % 2 != 1:
print((amnt // 1), "$1 Bills")
elif amnt == 1:
print((amnt // 1), "$1 Bills")
Related
I am making a couple of functions for taking pizza information in one, then using that information to calculate the price in the other function. When I run this though, it's having problems locating attributes in one of the functions, even after its run.
def calc_pizza_charge(size_cost, meats_cost, veg_cost, num_cost):
get_pizza_info.size = range(1, 4)
num_cost = get_pizza_info.quantity
total = (size_cost + meats_cost + veg_cost) * get_pizza_info.quantity
if get_pizza_info.size == 1:
size_cost = 6.50
if get_pizza_info.size == 2:
size_cost = 9.50
if get_pizza_info.size == 3:
size_cost = 11.50
meats_cost = (get_pizza_info.meats - 1) * 3.50
veg_cost = (get_pizza_info.veg - 1) * 1.50
print("Your total is $", "{:,.2f}".format(total))
def get_pizza_info(size, meats, veg, quantity):
size = int(input("Enter size from 1-3: "))
meats = int(input("Enter number of meat toppings "))
veg = int(input("Enter number of non-meat toppings "))
quantity = int(input("Enter number of these pizzas "))
if size >= 4:
size = 3
if size <= 1:
size = 1
if meats <= 1:
meats = 1
if veg <= 1:
veg = 1
Since you are not comfortable with other answers, Here a working code with minimal modifications to your code
def calc_pizza_charge():
size, meats, veg, quantity = get_pizza_info()
if size == 1:
size_cost = 6.50
elif size == 2:
size_cost = 9.50
else:
size_cost = 11.50
meats_cost = (meats - 1) * 3.50
veg_cost = (veg - 1) * 1.50
total = (size_cost + meats_cost + veg_cost) * quantity
print("Your total is $", "{:,.2f}".format(total))
def get_pizza_info():
size = int(input("Enter size from 1-3: "))
meats = int(input("Enter number of meat toppings "))
veg = int(input("Enter number of non-meat toppings "))
quantity = int(input("Enter number of these pizzas "))
if size >= 4:
size = 3
elif size <= 1:
size = 1
if meats <= 1:
meats = 1
if veg <= 1:
veg = 1
return size, meats, veg, quantity
if __name__ == '__main__':
calc_pizza_charge()
To be honest, I was extremely confused when I saw your code. I think you should review how functions work. Anyway, a few pointers:
In get_pizza_info you essentially ask for the order details: store it in some sort of data structure (I used dictionary)
In get_pizza_charge, you need to use the order details to compute the price of the pizza.
I have included my rewriting of your code:
def calc_pizza_charge():
pizza_info = get_pizza_info()
num_cost = pizza_info["quantity"]
size_cost = get_size_cost(pizza_info["size"])
meats_cost = (pizza_info["meats"] - 1) * 3.50
veg_cost = (pizza_info["veg"] - 1) * 1.50
total = (size_cost + meats_cost + veg_cost) * pizza_info["quantity"]
print("Your total is $", "{:,.2f}".format(total))
def get_size_cost(size):
if size == 1:
return 6.5
elif size == 2:
return 9.5
elif size == 3:
return 11.50
def get_pizza_info():
size = int(input("Enter size from 1-3: "))
meats = int(input("Enter number of meat toppings "))
veg = int(input("Enter number of non-meat toppings "))
quantity = int(input("Enter number of these pizzas "))
pizza_info = {}
pizza_info["size"] = max(min(size, 3), 1)
pizza_info["meats"] = max(1, meats)
pizza_info["veg"] = max(1, veg)
pizza_info["quantity"] = max(0, quantity)
return pizza_info
calc_pizza_charge()
You have defined all the attribute variables in get_pizza_info function and are trying to access them in calc_pizza_charge function.
Variables declared in a function are local to that function and cannot be accessed by any entity outside that function.
For your problem I would suggest defining a new class that contains both of these functions.
class Pizza:
def calc_pizza_charge(self):
num_cost = self.quantity
if self.size == 1:
size_cost = 6.50
if self.size == 2:
size_cost = 9.50
if self.size == 3:
size_cost = 11.50
else:
size_cost = 10
meats_cost = (self.meats - 1) * 3.50
veg_cost = (self.veg - 1) * 1.50
total = (size_cost + meats_cost + veg_cost) * self.quantity
print("Your total is $", "{:,.2f}".format(total))
def get_pizza_info(self):
self.size = int(input("Enter size from 1-3: "))
self.meats = int(input("Enter number of meat toppings "))
self.veg = int(input("Enter number of non-meat toppings "))
self.quantity = int(input("Enter number of these pizzas "))
if self.size >= 4:
self.size = 3
if self.size <= 1:
self.size = 1
if self.meats <= 1:
self.meats = 1
if self.veg <= 1:
self.veg = 1
piz = Pizza()
piz.get_pizza_info()
piz.calc_pizza_charge()
This code runs fine just like you wanted it to work. There were many fundamental mistakes in your code. I would suggest you to learn basics of functions and classes in Python.
I am trying to write a code in Python to where it outputs exact change using the fewest coins and one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. I also have to use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. When I input 45 and ran the code, I got an error saying (Your program produced no output). Here is my code:
total_change = int(input())
if total_change <= 0:
print('No change')
if total_change >= 100:
dollar = total_change//100
dollar_change = total_change % 100
if dollar == 1:
print(dollar + ' Dollar')
elif dollar > 1:
print(dollar + ' Dollars')
elif dollar_change >= 25:
quarter = dollar_change//25
quarter_change = dollar_change % 25
if quarter == 1:
print(quarter + ' Quarter')
elif quarter > 1:
print(quarter + ' Quarters')
elif quarter_change >= 10:
dime = quarter_change // 10
dime_change = quarter_change % 10
if dime == 1:
print(dime + ' Dime')
elif dime > 1:
print(dime + ' Dimes')
elif dime_change >= 5:
nickel = dime_change // 5
nickel_change = dime_change % 5
if nickel == 1:
print(nickel + ' Nickel')
elif nickel > 1:
print(nickel + ' Nickels')
elif nickel_change >= 1:
penny = nickel_change // 1
if penny == 1:
print(penny + ' Penny')
else:
print(penny + ' Pennies')
total = int(input())
if total == 0:
print("No change")
else:
denominations = [(100, "Dollar", "Dollars"), (25, "Quarter", "Quarters"), (10, "Dime", "Dimes"), (5, "Nickel", "Nickels"), (1, "Penny", "Pennies")]
for d in denominations:
coins = total // d[0]
total %= d[0]
if coins > 1:
print(f"{coins} {d[2]}")
elif coins == 1:
print(f"1 {d[1]}")
In this answer, I created a list full of tuples of all the coins and their values in cents. I then created a for loop which runs through all the tuples in the list, dividing the total removing the remainder for the number of coins
like this:
*coins = total // d[0] #returns the number of coins of the current iteration
Then, in order for the loop to continue to the next iteration and do the calculations correctly, I set the total in cents equal to the remainder of the total divided by the current iteration.
like this:
total %= d[0] #can also be written as total = total % d[0]
Then, I take the number of coins and check if the value is greater than one. If the conditional is met, it prints the number of coins followed by the corresponding "plural version" of the word.
like this:
if coins > 1:
print(f"{coins} {d[2]}")
#d[2] refers to the third item in the tuple of the current iteration
Finally, I use an else-if conditional to return 1 plus the "singular version" of the word
like this:
elif coins == 1:
print(f"1 {d[1]}")
#d[1] refers to the second item in the tuple of the current iteration
Your code has numerous problems that needed to be resolved, including the lack of a condition for input values 0 < total_change < 100, problems with indentation (the elif blocks should be aligned), unnecessary variables (you do not need variables like nickel_change and dime_change - total_change is all that matters), and you tried to print dollar + ' Dollar' even though dollar was a numeric variable.
I wanted to improve on the issues in your code and make it, well, functional, but without entirely rewriting your work. So, the basic framework of the code I'm going to provide is the same.
I used the method of recursion. I have the following function with all of your (cleaned) code:
def printCurrency(total_change):
dollar = total_change//100
dollar_change = total_change % 100
if dollar == 1:
print(str(dollar) + ' Dollar')
printCurrency(total_change-1*100)
elif dollar > 1:
print(str(dollar) + ' Dollars')
printCurrency(total_change-dollar*100)
elif dollar_change >= 25:
quarter = dollar_change//25
quarter_change = dollar_change % 25
if quarter == 1:
print(str(quarter) + ' Quarter')
printCurrency(total_change-1*25)
elif quarter > 1:
print(str(quarter) + ' Quarters')
printCurrency(total_change-quarter*25)
elif dollar_change >= 10:
dime = dollar_change // 10
dime_change = dollar_change % 10
if dime == 1:
print(str(dime) + ' Dime')
printCurrency(total_change-1*10)
elif dime > 1:
print(str(dime) + ' Dimes')
printCurrency(total_change-dime*10)
elif dollar_change >= 5:
nickel = dollar_change // 5
nickel_change = dollar_change % 5
if nickel == 1:
print(str(nickel) + ' Nickel')
printCurrency(total_change-1*5)
elif nickel > 1:
print(str(nickel) + ' Nickels')
printCurrency(total_change-nickel*5)
elif dollar_change >= 1:
penny = dollar_change // 1
if penny == 1:
print(str(penny) + ' Penny')
printCurrency(total_change-1*1)
else:
print(str(penny) + ' Pennies')
printCurrency(total_change-penny*1)
Notice how every time a line is printed, the function is ran again but after subtracting out the change we've already processed.
A few examples:
>>> printCurrency(45)
1 Quarter
2 Dimes
>>> printCurrency(101)
1 Dollar
1 Penny
>>> printCurrency(349)
3 Dollars
1 Quarter
2 Dimes
4 Pennies
And to tie this into your original framework with an input...
total_change = int(input())
if total_change <= 0:
print('No change')
if total_change >= 0:
printCurrency(total_change)
Let me know if you have any questions about the changes I've made to your code!
This is more of an answer that zybooks is looking for considering what it has taught up to this point. All that I have done here is decrement total_change each time I go down the list of coins. If there were no coins for that set then print a statement on the previous line.
total_change = int(input())
if total_change <= 0:
print('No change')
else:
dollar = total_change // 100
if dollar == 1:
print(dollar, 'Dollar')
total_change = total_change - (dollar * 100)
elif dollar <= 0:
print(end='')
else:
print(dollar, 'Dollars')
total_change = total_change - (dollar * 100)
quarter = total_change // 25
if quarter == 1:
print(quarter, 'Quarter')
total_change = total_change - (quarter * 25)
elif quarter <= 0:
print(end='')
else:
print(quarter, 'Quarters')
total_change = total_change - (quarter * 25)
dime = total_change // 10
if dime == 1:
print(dime, 'Dime')
total_change = total_change - (dime * 10)
elif dime <= 0:
print(end='')
else:
print(dime, 'Dimes')
total_change = total_change - (dime * 10)
nickel = total_change // 5
if nickel == 1:
print(nickel, 'Nickel')
total_change = total_change - (nickel * 5)
elif nickel <= 0:
print(end='')
else:
print(nickel, 'Nickels')
total_change = total_change - (nickel * 5)
penny = total_change // 1
if penny == 1:
print(penny, 'Penny')
total_change = total_change - (penny * 1)
elif penny <= 0:
print(end='')
else:
print(penny, 'Pennies')
total_change = total_change - (penny * 1)
I'm new in Python and i'm trying to make a program that withdraws money from a bank according to user input. The only works with $100, $50 and $20 bills.
If i type in 60, 80, 110 and other values the program goes for the highest bill available, and the withdraw money that is left the bank can't withdraw it...
Here's the code:
while True:
try:
money_amount = int(input('How much you want to withdraw? '))
if money_amount == 0:
print('Type in a valid value.')
continue
except ValueError:
print('Not accepted. Try again.')
else:
print(f'Withdraw amount: $ {money_amount:.2f}')
for bill_value in [100, 50, 20]:
bill_quantity = money_amount // bill_value # Divide saque // valor p/ encontrar quantia de cédulas
money_amount %= bill_value # Pega o resto da divisão de saque / valor. O que sobrar é calculado no próximo loop
print(f'$ {bill_value} Bills → {bill_quantity}')
if money_amount != 0:
print(f'\033[31mERROR!\033[m This bank uses only \033[33m $ 100, $ 50 and $ 20 bills!!!\033[m')
print('Try again.')
continue
break
print('\033[32mOperation Success\033[m')
If i add the value $ 1 to the Item list, the operation never fails...
[100, 50, 20, 1] - It works, but that's not a fix...
I would be grateful if someone could help me understand why this happens and what am i doing wrong.
Your withdraw logic has a fundamental flaw - you go from biggest to lowest denomiation. That does not work with the limited bills you allow.
You can only change money that
by itself divides by 20 without remainder
or when subtracted 50 (and not going negative) divides by 20 without remainder
100 is just a fancy way to deal 5 twenties
any other input can not be changed. You can code accordingly:
def canBeChanged(x):
return (x/20.0 == x//20.0) or x>=50 and ((x-50)/20.0 == (x-50)//20.0)
money = [1000, 110, 80, 60, 50, 20, 73, 10]
for m in money:
tmp = m
if canBeChanged(m):
change = []
isDiv20 = (tmp/20.0 == tmp//20.0) # divides by 20 without remainder
if not isDiv20:
change.append(50) # remove 50, now it divides
tmp -= 50
twenties = tmp // 20 # how many 20's left?
while twenties >=5: # how many 100 bills can we combine from 5 20's?
change.append(100)
twenties -= 5
while twenties: # how many 20's left?
change.append(20)
twenties -= 1
print(m, " == ", sorted(change))
else:
print(m, "can not be changed")
Output:
1000 == [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
110 == [20, 20, 20, 50]
80 == [20, 20, 20, 20]
60 == [20, 20, 20]
50 == [50]
20 == [20]
73 can not be changed
10 can not be changed
I have a problem with this code, this program should keep allowing you enter students until the number of passes reaches 8 or the total number of students reaches 10. However currently it just keeps asking for input and hence there is an infinite loop. How do I go about fixing this?
total_students=0
student_passes=0
student_failures=0
while (total_students <= 10) or (student_passes != 8):
result=int(input("Input the exam result: "))
if result>=50:
student_passes = student_passes + 1
else:
student_failures = student_failures + 1
total_students = total_students + 1
print (student_passes)
print (student_failures)
if student_passes >= 8:
print ("Well done")
Change or to and. While both are true you continue:
total_students=0
student_passes=0
student_failures=0
while (total_students != 10) and (student_passes != 8): # != or <
result=int(input("Input the exam result: "))
if result>=50:
student_passes += 1
else:
student_failures += 1
total_students +=1
print (student_passes)
print (student_failures)
you might have to revisit your code. I m not python expert, however I believe you should modify the condition for while loop.
such as while (total_students <= 10) or (student_passes <= 8):
this will resolve your problem.
total_students=0
student_passes=0
student_failures=0
while (total_students <= 10) or (student_passes <= 8):
result=int(input("Input the exam result: "))
if result>=50:
student_passes = student_passes + 1
else:
student_failures = student_failures + 1
total_students = total_students + 1
print (student_passes)
print (student_failures)
if student_passes >= 8:
print ("Well done")
You should use and instead of or to meet your requirement.
total_students=0
student_passes=0
student_failures=0
while (total_students <= 10 and student_passes < 8):
result=int(input("Input the exam result: "))
if result>=50:
student_passes = student_passes + 1
else:
student_failures = student_failures + 1
total_students = total_students + 1
print (student_passes)
print (student_failures)
if student_passes >= 8:
print ("Well done")
Here's my program. There are seven employees for which I am creating a paystub. I am trying to achieve a loop where it starts at num = 1 and go all the way through num = 7. When I run the program, however, nothing gets printed. Thoughts?
#initalize all variables
medPremiere = 400
fedRate = .20
stateRate = .05
FICA = .08
retirement = .06
**Tax rates and such**
#the processing module
num = 1
while num < 8:
if num ==1:
empNum = 1
empName = 'billybob'
hours = 40
rate = 50
num = num + 1
if num ==2:
empNum = 2
empName = 'superman'
hours = 55
rate = 40
num = num + 1
if num ==3:
empNum = 3
empName = 'hulk'
hours = 60
rate = 60
num = num + 1
if num ==4:
empNum = 4
empName = 'scoobie'
hours = 45
rate = 80
num = num + 1
if num ==5:
empNum = 5
empName = 'Sherry'
hours = 66
rate = 30
num = num + 1
if num ==6:
empNum = 6
empName = 'doctor'
hours = 88
rate = 90
num = num + 1
if num ==7:
empNum = 7
empName = 'ironman'
hours = 77
rate = 70
num = num + 1
These are 7 different employees for which I have to create paystubs for
#the calc module
#calculate gross pay
num ==1
while num < 8:
They get payed overtime and double overtime so I have to account for how many hours each employee has worked. Less than 41 hours they get payed regular, 41-60 hours they get paid overtime and more than 61 hours they get payed double overtime.
if hours <41:
gross = rate*hours
fedTax = gross*fedRate
stateTax = gross*stateRate
F = gross*FICA
K = gross*retirement
netPay = gross - fedTax - stateTax - F - K - medPremiere
print('Gross pay: ', gross)
print('Federal tax # 20%: ', fedTax)
print('State tax # 5%: ', stateTax)
print('FICA # 8%: ', F)
print('401K # 6%: ', K)
print('Net pay: $', netPay)
num = num + 1
Here I'm trying to make it go back to the list of numbers at the top and pull the information for the next employee.
if hours < 61:
gross = (40*hours) + (hours - 40)(1.5)(rate)
fedTax = gross*fedRate
stateTax = gross*stateRate
F = gross*FICA
K = gross*retirement
netPay = gross - fedTax - stateTax - F - K - medPremiere
print('Gross pay: ', gross)
print('Federal tax # 20%: ', fedTax)
print('State tax # 5%: ', stateTax)
print('FICA # 8%: ', F)
print('401K # 6%: ', K)
print('Net pay: $', netPay)
num = num + 1
if hours > 61:
gross = 40*hours + (hours-40)(1.5)(rate) + (hours - 60)(2)(rate)
fedTax = gross*fedRate
stateTax = gross*stateRate
F = gross*FICA
K = gross*retirement
netPay = gross - fedTax - stateTax - F - K - medPremiere
print('Gross pay: ', gross)
print('Federal tax # 20%: ', fedTax)
print('State tax # 5%: ', stateTax)
print('FICA # 8%: ', F)
print('401K # 6%: ', K)
print('Net pay: $', netPay)
num = num + 1
break
Is the calc module properly formatted, or is there a better way to go about this?
Above the line with while num < 8: you say num ==1. This instead should be num = 1, and should be put inline with the while statement like so:
num = 1
while num < 8:
That's why none of the print statements execute; because num is not being reset to be less than 8.
Also, a stylistic point that can help you avoid errors (and it does the dirty work of initializing and incrementing counter vars for you), you can do this:
for num in range(1,8):
...
print num
...
This code can't possibly work as intended. You go over the first loop 7 times, rebinding the same variables and doing nothing else. At the end of that, you've got employee 7's values. Then you go over the second loop 7 times, using employee 7's values each time. (Then, because your indentation is incorrect, you don't do anything for an employee with >= 41 hours, so you do nothing 7 times.)
This is a very awkward way to structure your program, and it will be a lot easier to fix it if you restructure it.
First, if you want to loop over all of the numbers in [1, 8), use a for loop:
for num in range(1, 8):
This removes a whole lot of lines of extra code where you could get things wrong—including the one you actually did get wrong.
Next, you need to actually do something for each employee. While you could move the first loop into a function and put a yield empNum, empName, hours, rate, num after each one, this is making things far more complicated than they need to be. What you want is a function that can be called with a number and just return the right values for that number. Then you don't need a loop here at all.
But that function is already written for you, if you use the right data structure: it's just indexing.
For example, if you replace the first loop with this:
employees = {}
employees[1] = dict(empNum = 1,
empName = 'billybob',
hours = 40,
rate = 50)
employees[2] = dict(empNum = 2,
# etc.
… then the second loop can just do this:
for employee in employees.values():
if employee['hours'] < 41:
gross = employee['rate'] * employee['hours']
fedTax = gross*fedRate
stateTax = gross*stateRate
F = gross*FICA
K = gross*retirement
netPay = gross - fedTax - stateTax - F - K - medPremiere
print('Gross pay: ', gross)
print('Federal tax # 20%: ', fedTax)
print('State tax # 5%: ', stateTax)
print('FICA # 8%: ', F)
print('401K # 6%: ', K)
print('Net pay: $', netPay)
if employee['hours'] < 61:
# ...
But note that you're not actually using the keys for anything, so you must as well just use a list instead of a dict. (That way you also guarantee that you always iterate the employees in the same order you create them.) For example:
employees = [
dict(empNum = 1,
empName = 'billybob',
hours = 40,
rate = 50),
dict(empNum = 2,
# etc.
And now, you don't need for employee in employees.values():, just for employee in employees:.
Meanwhile, the indentation problem wouldn't be possible if you used elif and else. In this code:
if employee['hours'] < 41:
gross = employee['rate'] * employee['hours']
# ... a bunch more code
if employee['hours'] < 61:
gross = employee['rate'] * employee['hours']
# ... a bunch more code
if employee['hours'] > 61:
gross = employee['rate'] * employee['hours']
… everything compiles and runs, but you can never get into the last block, because hours can't be less than 41 and also be more than 60. But in this code:
if employee['hours'] < 41:
gross = employee['rate'] * employee['hours']
# ... a bunch more code
elif employee['hours'] < 61:
gross = employee['rate'] * employee['hours']
# ... a bunch more code
elif employee['hours'] > 61:
gross = employee['rate'] * employee['hours']
You will get a SyntaxError if you get the indentation wrong, because there's no if at the same level as the elif, which is easier to debug.
Next, note that 61 is not less than 41, or less than 61, or greater than 61, so nothing will happen for anyone who works 61 hours. You could fix that by using >= 61 for the last check. Or, even more simply, just using else instead of elif.
Next, whenever you write the same line of code more than twice, you should look for a way to refactor it. Almost all of the details are identical between the three cases; only the first line is different. Besides being harder to read, repetitive code is also harder to get right, and harder to maintain. For example, at some point, you're going to have a bug, and fix it in one copy but not the other two.
Also, you can't multiply two numbers in Python by adjoining them; you need to use the * operator, like this:
gross = 40*hours + (hours - 40) * 1.5 * rate + (hours - 60) * 2 * rate
Finally, your equations are wrong. If someone works 50 hours, you're going to pay them 40 hours at $1/hour because you forgot to multiply the first term by rate, and then you're going to pay them an extra 150% for the next 15 hours instead of an extra 50%.
Putting it all together, replace the first loop with the list of dictionaries above, then replace the second loop with this:
for employee in employees:
gross = rate * hours
if hours > 40:
gross += rate * (hours - 40) * 0.5 * rate
if hours > 60:
gross += rate * (hours - 60) * 0.5 * rate
fedTax = gross*fedRate
stateTax = gross*stateRate
F = gross*FICA
K = gross*retirement
netPay = gross - fedTax - stateTax - F - K - medPremiere
print('Gross pay: ', gross)
print('Federal tax # 20%: ', fedTax)
print('State tax # 5%: ', stateTax)
print('FICA # 8%: ', F)
print('401K # 6%: ', K)
print('Net pay: $', netPay)
And that's your whole program.