0

The code below, I am trying to convert a string to int in my give_raise method. I know it's probably something simple I am missing, but I am stumped. What would be the proper syntax to convert the string to int and add that bonus to my annual salary total?

class Employee():
    """Stores an employee's data"""

    def __init__(self, first_name, last_name, annual_salary):
        """Employee values"""
        self.first_name = first_name
        self.last_name = last_name
        self.annual_salary = annual_salary

    def give_raise(self, annual_salary = 40000):
        """Sets a default salary with the option to add more"""
        choice = input("Do you want to add a bonus to the annual salary of more than 5000 dollars? y\n")
        if choice == 'n':
            annual_salary += 5000
        else:
            bonus = input("Please enter your bonus amount: ")
            int(bonus)
            annual_salary + bonus = annual_salary

        print(annual_salary)

my_Employee = Employee('Harry', 'Scrotum', 40000)
my_Employee.give_raise()
D.Wes
  • 27
  • 1
  • 1
  • 10

1 Answers1

0

The line of code int(bonus) does not assign the integer to a variable. You need to assign it to a variable and use it in your calculation.

IE

integer_bonus = int(bonus)
annual_salary = integer_bonus + annual_salary

Note: I swapped your annual_salary assignment. The way you had it was awkward.

Doug
  • 3,472
  • 3
  • 21
  • 18
  • Thanks Doug! Worked perfect. Now on to part 2 of the exercise, writing a test case for it – D.Wes Mar 07 '17 at 02:43