Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
class Employee:

    raiseAmount=1.04

    def __init__(self,first,last,pay):
        self.first=first
        self.last=last
        self.email=first+'.'+last+'@gmail.com'
        self.pay=pay

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

    def applyRaise(self):
        self.pay = int(self.pay*self.raiseAmount)

class Developer(Employee):
    pass

dev1=Employee('Corey','Schafer','70000')
dev2=Developer('Test','Employee','60000')

#print(dev1.email)
#print(dev2.email)

print(dev1.pay)
dev1.applyRaise()
print(dev1.pay)


This is my pyhton code which i tried to run in the terminal......but it is showing an error which is
PS C:\Users\dark_phoenix\lpthw> python oop.py
70000
Traceback (most recent call last):
  File "oop.py", line 27, in <module>
    dev1.applyRaise()
  File "oop.py", line 15, in applyRaise
    self.pay = int(self.pay*self.raiseAmount)
TypeError: can't multiply sequence by non-int of type 'float'


What I have tried:

I tried to change the datatype of selfRaise to int but it is also not working.
Posted
Updated 31-May-18 23:02pm
v2

1 solution

Python
dev1=Employee('Corey','Schafer','70000')

The quote characters around the number makes Python treat it as a string, and not as a number. Your code should be:
Python
dev1=Employee('Corey','Schafer', 70000) # no quotes around 7000
 
Share this answer
 
Comments
CPallini 1-Jun-18 5:31am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900