Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- class Employee():
- def __init__(self,name,rate,hours):
- self.name = name
- self.rate = rate
- self.hours = hours
- class SalariedEmployee(Employee):
- def calculatePay(self):
- compensation = self.rate/40*self.hours
- return compensation
- class HourlyEmployee(Employee):
- def calculatePay(self):
- compensation = self.rate*self.hours
- return compensation
- def main():
- total = {}
- salaried = 0
- hours = 0
- while True:
- while True:
- try:
- name = input("Enter employees's name: ")
- name = name.lower().split()
- name = [item.capitalize() for item in name]
- name = ' '.join(name)
- classification = input("Enter employee's classification(Salaried or Hourly): ").capitalize()
- for letter in name:
- if letter not in string.ascii_letters and letter != ' ':
- raise Exception
- for letter in classification:
- if letter not in string.ascii_letters:
- raise Exception
- except:
- print('Only letters are allowed, please try again.')
- else:
- if classification == 'Salaried':
- while True:
- try:
- time = float(input('Enter hours worked: '))
- pay = float(input('Enter weekly salary: '))
- except:
- print('Only numbers are allowed, please try again.')
- else:
- break
- total[name] = SalariedEmployee.calculatePay(Employee(name,pay,time))
- salaried+=1
- hours += time
- break
- elif classification == 'Hourly':
- while True:
- try:
- time = float(input('Enter hours worked: '))
- pay = float(input('Enter hourly wage: '))
- except:
- print('Only numbers are allowed, please try again.')
- else:
- break
- total[name] = HourlyEmployee.calculatePay(Employee(name,pay,time))
- hours += time
- break
- else:
- print('Invalid input, please try again')
- while True:
- ask = input('Do you want to continue? Y/N: ')
- if ask.upper() == 'N':
- for key in total:
- print(f'{key}: ${total[key]}')
- print(f'Number of employees: {len(total)}')
- print(f'Number of salaried employees: {salaried}')
- print(f'Total payroll: {sum(total.values())}')
- print(f'Average number of hours worked per employee: {hours/len(total)}')
- break
- elif ask.upper() != 'Y':
- print('Invalid input, please try again')
- else:
- break
- if ask.upper() =='N':
- break
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement