Aug-20-2023, 11:10 AM
(This post was last modified: Aug-20-2023, 11:10 AM by iwantyoursec.)
Hello all,
I just started my Python journey a couple of days ago. I typed the following code exactly as shown in the book I'm reading, but it returns an error message and I can't seem to figure out why.
Here's the code:
When I type:
If I type:
However, when I type:
Any help is very much appreciated. Thanks.
I just started my Python journey a couple of days ago. I typed the following code exactly as shown in the book I'm reading, but it returns an error message and I can't seem to figure out why.
Here's the code:
class Staff: def __init__ (self, pPosition, pName, pPay): self.position = pPosition self.name = pName self.pay = pPay print ("Creating Staff object") def __str__ (self): return "Position = %s, Name = %s, Pay = %d" %(self.position, self.name, self.pay) def calculatePay (self): prompt = "\nEnter number of hours worked for %s: " %(self.name) hours = input(prompt) prompt = "Enter the hourly rate for %s: " %(self.name) hourlyRate = input(prompt) self.pay = int(hours) * int(hourlyRate) return self.payI then create an object by typing the following:
officeStaff1 = Staff ('Basic', 'Michael', 1)..to which I get the following message "Creating Staff Object"
When I type:
officeStaff1.nameI see Michael.
If I type:
officeStaff1.positionI see Basic
However, when I type:
officeStaff1.calculatePay()The error message I am getting is:
Error:Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
officeStaff1.calculatePay()
File "/Users/mikemusicmbp2/Desktop/classdemo.py", line 12, in calculatePay
prompt = "\nEnter number of hours worked for %s: " %(self.name)
TypeError: 'str' object is not callable
I've tried using comments to remove one line of code at a time in hopes that I'll see some type of clue. However, that hasn't worked. I have also tried Googling answers and that hasn't worked either. I don't have any programmer friends that I can ask so here I am. I have zero programming experience and have hit a wall.Any help is very much appreciated. Thanks.