我在终端中运行以下Python 3.6代码时遇到错误....有人帮助我。 [英] I'm facinng an error while running the following Python 3.6 code in terminal....someone plzz help me.

查看:83
本文介绍了我在终端中运行以下Python 3.6代码时遇到错误....有人帮助我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)





这是我的pyhton代码,我试图在终端中运行......但它显示的错误是

PS C:\\ \\Users\dark_phoenix\lpthw> python oop.py



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'





我尝试过:



我试图将selfRaise的数据类型更改为int但它也无效。



What I have tried:

I tried to change the datatype of selfRaise to int but it is also not working.

推荐答案

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



数字周围的引号字符使Python将其视为字符串,而不是数字。您的代码应该是:


The quote characters around the number makes Python treat it as a string, and not as a number. Your code should be:

dev1=Employee('Corey','Schafer', 70000) # no quotes around 7000


这篇关于我在终端中运行以下Python 3.6代码时遇到错误....有人帮助我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆