我正在使用Python 3中的类,而且我很难与他们合作。我在这里有两个程序(一个正在导入另一个)

这个想法是,你正在制作一份员工名单,你有三类员工每小时,工资和志愿者。

我似乎在每个课程中都遇到了我的show_pay问题。我也知道在我的Salary类中,我试图用一个整数来分割字符串,但是我写代码的方式我不太清楚如何解决它。

我的小时班似乎没有列入清单。

先谢谢你。我真的很困惑,我试图通过这个项目。

第一个项目(员工)

#set global constant

SHIFT_2 = 0.05

SHIFT_3 = 0.10

#person class

class Person:

#initialize name, ID number, city

def __init__(self, name, ID, city):

self.__ID = ID

self.__name = name

self.__city = city

#display employee name

def show_person(self):

print('Name:', self.__name)

print('ID:', self.__ID)

print('City:', self.__city)

#display salary

def show_pay(self):

print('I make lots of money')

#return formatting

def __str__(self):

name_string = '(My name is ' + self.__name +')'

return name_string

# Hourly employee class

class Hourly(Person):

#initialize method calls superclass

def __init__(self, name, ID, city, base_pay, shift):

Person.__init__(self, name, ID, city)

self.__base_pay = base_pay

self.__shift = shift

#show_pay overrides the superclass and displays hourly pay rates

def show_pay(self):

if self.__shift == 1:

print('My salary is ', self.__base_pay)

elif self.__shift == 2:

print('My salary is ', (self.__base_pay * SHIFT_2) + self.__base_pay)

elif self.__shift == 3:

print('My salary is ', (self.__base_pay * SHIFT_3) + self.__base_pay)

#salary employee class

class Salary(Person):

#intialize method calls superclass

def __init__(self, name, ID, city, ann_salary):

Person.__init__(self, name, ID, city)

self.__salary = ann_salary

#show pay overrides superclass and displays salary pay rates

def show_pay(self):

print('I make ', self.__salary)

print('which is ', self.__salary // 26, 'every two weeks.')

#volunteer employee class

class Volunteer(Person):

def __init__(self, name, ID, city):

Person.__init__(self, name, ID, city)

def show_pay(self):

print('I am a volunteer so I am not paid.')这是主要的程序

import employee

def main():

#create list

employees = make_list()

#display list

print('Here are the employees.')

print('-----------------------')

display_list(employees)

def make_list():

#create list

employee_list = []

#get number of hourly employees

number_of_hourly = int(input('\nHow many hourly will be entered? '))

for hourly in range(number_of_hourly):

#get input

name, ID, city = get_input()

base_pay = input('Enter employee base pay: ')

shift = input('Enter employee shift 1,2, or 3: ')

#create object

Hourly = employee.Hourly(name, ID, city, base_pay, shift)

#add object to list

employee_list.append(Hourly)

#get number of salary employees

number_of_salary = int(input('\nHow many salary will be entered? '))

for salary in range(number_of_salary):

#get input

name, ID, city = get_input()

ann_salary = input('Enter employee annual salary: ')

#create object

salary = employee.Salary(name, ID, city, ann_salary)

#add object to list

employee_list.append(salary)

#get volunteers

number_of_volunteers = int(input('\nHow many other volunteers will be entered? '))

for volunteers in range(number_of_volunteers):

#get info

name, ID, city = get_input()

#create object

volunteer = employee.Person(name, ID, city)

#add object to list

employee_list.append(volunteer)

#invalid object

employee_list.append('\nThis is invalid')

#return employee_list

return employee_list

def get_input():

#input name

name = input("Employee's name: ")

#validate

while name == '':

print('\n Name is required. Try again.')

name = input("Employee's name: ")

ID_valid = False

ID = input("Employee's ID: ")

while ID_valid == False:

try:

ID = float(ID)

if ID > 0:

ID_valid = True

else:

print("\nID must be > 0. Try again.")

ID = input("Employee's age: ")

except ValueError:

print("\nID must be numeric. Try again.")

ID = input("Employee's ID: ")

#get city

city = input("Enter employee's city of residence: ")

#return values

return name, ID, city

def display_list(human_list):

#create for loop for isinstance

for human in human_list:

#create isinstance

if isinstance(human, employee.Person):

print(human)

human.show_person()

human.show_pay()

print

else:

print('Invalid employee object')

#call main function

main()

用python定义一个员工类_Python与类一起工作相关推荐

  1. python定义一个空数组_python数组 1_python 数组最后一个元素_python定义一个空数组 - 云+社区 - 腾讯云...

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 感悟: 1.python列表操作里不允许变量类型的指针2.case1类似于冒泡排 ...

  2. 用python定义一个员工类_python类的定义和使用

    类的定义: 类是用来描述具有相同的属性和方法的对象的集合.它定义了该集合中的每个对象所共有的属性和方法.对象时类的实例. 二.Python创建类: 使用class语句来创建一个新类,class之后为类 ...

  3. 用python定义一个员工类_python3 类的定义

    1.面向过程和面向对象 1.1 面向过程 面向过程的程序设计的核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点是:极大的 ...

  4. python定义一个整数变量_python循环定义多个变量的实例分析

    python循环定义多个变量方法 我们可能会时长碰到这样一个场景,计算得到一个非固定值,需要根据这个值定义相同数量个变量. 实现方式的核心是exec函数,exec函数可以执行我们输入的代码字符串. e ...

  5. python定义一个求和函数_Python定义函数实现累计求和操作

    一.使用三种方法实现0-n累加求和 定义函数分别使用while循环.for循环.递归函数实现对0-n的累加求和 1.使用while循环 定义一个累加求和函数sum1(n),函数代码如下: 2.使用 f ...

  6. 用python定义一个员工类_Python:定义一个只有整数定义的类

    使用MutableSet ABC,这是非常低效但完整的实现: import collections class MySet(collections.MutableSet): def __init__( ...

  7. python定义一个1xn矩阵_Python实现的矩阵类实例

    本文实例讲述了Python实现的矩阵类.分享给大家供大家参考,具体如下: 科学计算离不开矩阵的运算.当然,python已经有非常好的现成的库: 我写这个矩阵类,并不是打算重新造一个轮子,只是作为一个练 ...

  8. python定义一个整数变量_Python变量与常量

    1.什么是变量 a=1,其中 a 就是变量名称,1 就是它的值.在程序运行过程中,变量的值一般都会发生改变,内存中会专门开辟一段空间,用来存放变量的值,而变量名将指向这个值所在的内存空间.与变量相对的 ...

  9. python定义一个空数组_python如何创建空数组?

    Python创建空数组的三种方式: 1.numpy指定形状为0 实际上,empty生成的数组当然可以为空,只要我们指定了相应的形状.例如,如果我们传入数组的形状参数为(0,3),则可以生成目标空数组: ...

  10. python定义一个全局字典_Python字典操作详细介绍及字典内建方法分享

    创建 方法一: >>> dict1 = {} >>> dict2 = {'name': 'earth', 'port': 80} >>> dict ...

最新文章

  1. 检测到包降级: Microsoft.Extensions.Configuration.Abstractions 从 2.1.1 降 2.1.0
  2. 花17000元在元宇宙里用Linux?这款VR电脑开启预售,头显就是主机的那种,搭载英特尔i7...
  3. CentOS下Redis的安装
  4. 滴滴基于 Flink 的实时数仓建设实践
  5. GreenPlum的并行查询优化策略
  6. nginx配置文件中的location中文详解
  7. [Leedcode][JAVA][第69题][x的平方根][二分查找][数学]
  8. bzoj 1179: [Apio2009]Atm(Trajan+SPFA)
  9. 数值积分NIntegrate中的具体算法
  10. 跟着AlphaGo 理解深度强化学习框架
  11. AutoCAD2020修改 图层名称
  12. oracle shared_pool_size 0,Oracle 参数shared_pool_size
  13. Python进行高斯积分(Gaussian integral)
  14. 【工程源码】使用华邦的SPI FLASH作为EPCS时固化NIOS II软件报错及解决方案
  15. SaaS的优势和劣势
  16. linux sox录音时间控制,SOX的一些命令和kaldi使用sox音频数据增强
  17. 读书笔记:吉檀迦利:致我们无处安放的心灵
  18. NVIDIA_CUDA和AMD_AMD APP
  19. JS中的$().each
  20. 在网页中使用矢量图标

热门文章

  1. BadEncoder: Backdoor Attacks to Pre-trained Encoders in Self-Supervised Learning 论文笔记
  2. 计算机运行但屏幕黑屏,电脑显示器黑屏,教您电脑主机运行正常显示器黑屏怎么办...
  3. fiddler 证书错误
  4. 2021-2027全球与中国双联式过滤器外壳市场现状及未来发展趋势
  5. 办公本推荐计算机专业,口碑最好的办公笔记本排行 五款最受欢迎的办公笔记本推荐...
  6. Python准备篇:第三方库管理
  7. php strict,PHP 5.4中的E_STRICT和E_ALL有什么区别?
  8. MTK Android LCD模块驱动
  9. win10系统声音很大,微信等应用声音很小的问题
  10. 如果矩阵中存在字符用C语言,面试中常见的数据结构与算法题整理,想当架构师,数据结构与算法不过关可不行(数组+字符串,共60题)...