没有合适的资源?快使用搜索试试~ 我知道了~
Python编程汇总 Python基础知识 1. 介绍关于⾃⼰的⼀些详细信息 ⾸先通过⽤户终端输⼊⾃⼰的学号、姓名、性别、出⽣⽇期、⽤户名、所修的课程和所选的教材等基本信息。 然后判断⾃⼰的出⽣年份是否为闰年、创建的⽤户名是否合法。 最后通过⽤户终端将所有信息和判断结果输出。 代码: student = input("Please enter your student ID:") name = input("Please enter your name:") gender = input("Please enter your gender:") birthday = input("Please enter your birthday(2020/01/01):") username = str(input("Please enter your username:")) course = input("Please enter your course:") textbook = input("Please enter your textbook:") print("student ID:"
资源推荐
资源详情
资源评论
Python编程汇总
Python基础知识
1. 介绍关于⾃⼰的⼀些详细信息
⾸先通过⽤户终端输⼊⾃⼰的学号、姓名、性别、出⽣⽇期、⽤户名、所修的课程和所选的教材等基本信息。
然后判断⾃⼰的出⽣年份是否为闰年、创建的⽤户名是否合法。
最后通过⽤户终端将所有信息和判断结果输出。
代码:
student = input("Please enter your student ID:")
name = input("Please enter your name:")
gender = input("Please enter your gender:")
birthday = input("Please enter your birthday(2020/01/01):")
username = str(input("Please enter your username:"))
course = input("Please enter your course:")
textbook = input("Please enter your textbook:")
print("student ID:", student)
print("name:", name)
print("gender:", gender)
print("birthday:", birthday)
print("username:", username)
print("course:", course)
print("textbook:", textbook)
year = int(birthday[:4:])
boolyear = (year % 4) == 0 and (year % 100) != 0 or (year % 400) == 0
if boolyear:
print("出⽣年%d 是闰年" %year)
else:
print("出⽣年%d 不是闰年" %year)
yingwen="abcdefghijklmnopqrstuvwxyz"
xiahuaxian="_"
shuzi="1234567890"
if len(username) == 3:
if username[0] in yingwen+xiahuaxian:
if username[1] in yingwen+xiahuaxian+shuzi:
if username[2] in yingwen+shuzi:
print("⽤户名:%s 合法" % username)
else:
print("⽤户名:%s 不合法,第三个字符必须是⼩写字母或数字" % username)
else:
print("⽤户名:%s 不合法,第⼆个字符必须是⼩写字母或下划线或数字" % username)
else:
print("⽤户名:%s 不合法,第⼀个字符必须是⼩写字母或下划线" % username)
else:
print("⽤户名:%s 不合法,字符长度超出3" %username)
注意:光会理论填空是不够的,在此送⼤家⼀套2020最新Python全栈实战视频教程, 免费获取⼀起进步哦!注意:光会理论填空是不够的,在此送⼤家⼀套2020最新Python全栈实战视频教程, 免费获取⼀起进步哦!
2. 内部竞聘
在公司内部竞聘中,候选⼈⼩明和⼩强竞聘部门副经理,考核的选项共有5项,分别是部门同事投票、去年业绩、年龄、在公司年份、
竞聘演讲得分。评分规则如下:
1. 部门同事投票,每⼀票得3分
2. 业绩得分,每拿业绩200000,得⼀分
3. 年龄,年龄每⼩⼀岁得2分
4. 在公司年份,没长⼀年得5分
5. 竞聘演讲,得分为实际演讲得分
各项得分如下:
请计算两位候选⼈的最终得分,评选出部门副经理
提⽰:将信息保存在变量中;使⽤运算符进⾏计算
代码:
sum1 = 0
sum2 = 0
piao1 = 11
piao2 = 7
ye1 = 586319
ye2 = 811064
age1 = 34
age2 = 27
year1 = 10
year2 = 4
score1 = 81
score2 = 83
sum1 = (piao1/1)*3
sum1 = int((ye1/200000))*1 + sum1
sum2 = (piao2/1)*3
sum2 = int((ye2/200000))*1 + sum2
if age1 < age2:
sum1 = (age2 - age1) * 2 + sum1
else:
sum2 = (age1 - age2) * 2 + sum2
if year1 > year2:
sum1 = (year1 - year2) * 5 + sum1
else:
sum2 = (year2 - year1) * 5 + sum2
sum1 = score1 + sum1
sum2 = score2 + sum2
print("⼩明得分:", sum1, "⼩强得分:", sum2)
3. 有四个字符串:
’ haPPy BiRthDAy To u’
‘Happy biRthDAy To you’
’ haPpy BirThdAy 2 deAr LiLi’
’ happy birthday 2 u’
可以看出这4个字符串连起来是⼀⾸歌,但不⼯整,并夹杂着很多⼝语,请将上述字符串修改为以下规范格式,并输出。
happy birthday to you
happy birthday to yoyou
happy birthday to dear lili
happy birthday to you
代码:
str1 = ' haPPy BiRthDAy To u'
str2 = 'Happy biRthDAy To you'
str3 = ' haPpy BirThdAy 2 deAr LiLi'
str4 = ' happy birthday 2 u'
str1 = str1.strip().lower().replace('u', 'you')+'\n'
str2 = str2.strip().lower().replace('you', 'yoyou')+'\n'
str3 = str3.strip().lower().replace('2', 'to')+'\n'
str4 = str4.strip().lower().replace('2', 'to').replace('u', 'you')+'\n'
print(str1+str2+str3+str4)
剩余16页未读,继续阅读
资源评论
是空空呀
- 粉丝: 167
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功