Q:

Getting error "can't multiply sequence by non-int of type 'float'"?

Here in my program, I have given employee pay in string and I am multiplying that amount with int. 
Getting an error:

TypeError: can't multiply sequence by non-int of type 'float'

Please hep me out in debugging this.
class Employee:

    raise_amt=1.2 # class variable

    def __init__(self,first,last,pay): 
        self.first=first
        self.last = last # instance variables
        self.pay = pay
        self.email = first+"."+last+"@company.com"

    def fullname(self):
        return '{}{}'.format(self.first,self.last)

    def apply_raise(self):
        self.pay= int(self.pay * self.raise_amt)

    @classmethod # alter the raise amt 
    def set_raise_amt(cls,amount):
        cls.raise_amt=amount

    @classmethod 
    def from_string(cls,emp_str):
        first,last,pay= emp_str.split('-')
        return cls(first,last,pay)

emp_str_1='Nanda-kishor-90000' #values are in string
new_emp_1=Employee.from_string(emp_str_1)

Employee.set_raise_amt(2.2)

print(new_emp_1.raise_amt)
print(new_emp_1.pay)
new_emp_1.apply_raise()
print('after raise:',new_emp_1.pay)

Output:
Traceback (most recent call last):
  File "C:/Users/nanda.v/PycharmProjects/Python basics/practice continue and break statements.py", line 39, in <module>
    new_emp_1.apply_raise()
2.2
  File "C:/Users/nanda.v/PycharmProjects/Python basics/practice continue and break statements.py", line 19, in apply_raise
    self.pay= int(self.pay * self.raise_amt)
90000
TypeError: can't multiply sequence by non-int of type 'float'

A:

Python does not automatically convert strings to numbers.  If you want it to be a float or an integer, you need to say so.  Python doesn't always have a problem with multiplying strings, though.  Multiplying a string just repeats it:
>>> my_string = 'blah'
>>> my_string * 2
'blahblah'

The problem in your code is that self.raise_amt is a float.  It doesn't make sense to repeat a string a decimal number of times, so you get an error.
What you need is to convert pay to a float when you get it.  That is simply: float(pay) in your __init__:
self.pay = float(pay)

This will error if the pay argument is not a valid string, but that should be expected.

