《Python编程》第五章部分课后练习题#5-5 外星⼈颜⾊:
junit下载教程
代码:
#5-5 外星⼈颜⾊
def get_points(alien_color):
point = 0
if alien_color == 'green':
point = 5
python基础代码练习elif  alien_color == 'yellow':
point = 10
else:
point = 25
message = 'You get ' + str(point) + ' points!'
文组词print(message)
alien_color = 'green'
get_points(alien_color)
alien_color = 'yellow'
get_points(alien_color)
alien_color = 'red'
get_points(alien_color)
输出:
You get 5 points!
You get 10 points!
美国第一岛链军事部署图
You get 25 points!
#5-8 以特殊⽅式跟管理员打招呼:
代码:
#5-8 以特殊⽅式跟管理员打招呼
users = ['Aaron', 'Caldwell', 'Kobe', 'Irving', 'admin']
users.append('James')
for user in users:
message = ''
if user == 'admin':
message = "Hello admin, would you like to see a status report?"
else:
message = "Hello " + user + ", thank you for logging in again"
print(message)
输出:
Hello Aaron, thank you for logging in again
Hello Caldwell, thank you for logging in again
Hello Kobe, thank you for logging in again
Hello Irving, thank you for logging in again
Hello admin, would you like to see a status report?
Hello James, thank you for logging in again
#5-10 检查⽤户名:
代码:
#5-10 检查⽤户名
current_users = ['Aaron', 'Caldwell', 'Kobe', 'Irving', 'James']
new_users = ['Kobe', 'Harden', 'JAMES', 'George', 'Davis']
for user in new_users:
texturehavenmessage = user.title()
if user.title() in current_users:
message += ', this name has been registered before,'java可变参数
message += 'Please try another one.'
else:
message += ', what a wonderful name!'
print(message)
输出:
Kobe, this name has been registered before,Please try another one. Harden, what a wonderful name!
James, this name has been registered before,Please try another one. George, what a wonderful name!
Davis, what a wonderful name!
#5-11 序数:
代码:
#5-11 序数
for num in range(1, 10):
message = str(num)
if num == 1:
message += 'st'
elif num == 2:
message += 'nd'
elif num == 3:
message += 'rd'
else:
message += 'th'
print(message)
输出:
1st
2nd
3rd
4th
5th
6th
7th
8th
9th

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。