当前位置:   article > 正文

Python语法入门_:输入用户姓名,输出用户名字的首字母后面加上最多7位作为用户名。

:输入用户姓名,输出用户名字的首字母后面加上最多7位作为用户名。

一:下面我就以几个小程序入门:

PS:先举几个例子复习一下有关类,继承的知识:
(1)类

class Employee:
    empCount=0

    def __init__(self,name,salary):
        self.name=name
        self.salary=salary
        Employee.empCount+=1

    def displayCount(self):
        print "Total Employed %d" %Employee.empCount

    def displayEmployee(self):
        print "name:", self.name, ",salary:", self.salary

emp1=Employee("wang",10000)
emp2=Employee("zhang",8000)
emp1.displayEmployee()
emp2.displayEmployee()
print "Total Employee %d" %Employee.empCount
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

(2)继承

class Employee:
    empCount=0
    def __init__(self,name,salary):
        self.name=name
        self.salary=salary
        Employee.empCount+=1

    def displayCount(self):
        print "Total Employed %d" %Employee.empCount

    def show(self):
        print "parentWay"
class Employee1(Employee):
    def __init__(self):
        print "childMethod"
    def displayCount(self):
        print "childWay"
emp1=Employee("wang",10000)
emp2=Employee("zhang",8000)

emp3=Employee1()
emp3.displayCount()
emp3.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

1.问题:在温度刻画的不同体系中,摄氏度以1标准大气压下水的结冰点为0度,沸点为100度。华氏度以1标准大气压下水的结冰点为32度,沸点为212度。如何利用程序辅助进行摄氏度和华氏度之间的转换。
分析:根据华氏和摄氏温度定义,其单位刻度对应温度关系为(212-32)/(100-0)=1.8,转换公式如下:
C = ( F – 32 ) / 1.8
F = C * 1.8 + 32

#tempConvert.py
from __builtin__ import str
input_st
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/1005848
推荐阅读
相关标签
  

闽ICP备14008679号