EduCoder实践课程
实践课程——Python程序设计入门答案
程序设计入门答案
记:由于疫情暂时返不了校,然后学校大四毕业年级布置了在线实训的任务,我选择了实践课程Python程序设计入门。以前
没有学过,可能是之前有过acm经验,感觉Python挺好入门的,把自己学习过程中的代码记录下来,一是为了自己写报告方
便,二来大家可以作为参考代码,如果有更好的代码可以留言,大家相互学习。本文持续更新~
1、Python初体验
第1关:Hello Python,我来了!
# coding=utf-8
# 请在此处添加代码完成输出“Hello Python”,注意要区分大小写!
########## Begin ##########
print("Hello Python")
########## End ##########
2、 Python 入门之字符串处理
第1关:字符串的拼接:名字的组成
# coding=utf-8
# 存放姓氏和名字的变量
first_name = input()
last_name = input()
# 请在下面添加字符串拼接的代码,完成相应功能
########## Begin ##########
full_name=first_name+" "+last_name
print(full_name)
########## End ##########
第2关:字符转换
# coding=utf-8
# 获取待处理的源字符串
source_string = input()
# 请在下面添加字符串转换的代码
########## Begin ##########
source_string1=source_string.strip()
transform_string=source_string1.title()
print(transform_string)
lenth=len(transform_string)
print(lenth)
########## End ##########
第3关:字符串查找与替换
# coding = utf-8
source_string = input()
# 请在下面添加代码
########## Begin ##########
print(source_string.find('day'))
new_string=source_string.replace('day','time')
print(new_string)
new_string2=new_string.split(' ')
print(new_string2)
########## End ##########
3、Python 入门之玩转列表
第1关:列表元素的增删改:客人名单的变化
# coding=utf-8
# 创建并初始化Guests列表
guests = [] while True:
try:
guest = input()
guests.append(guest)
except:
break
# 请在此添加代码,对guests列表进行插入、删除等操作
########## Begin ##########
lenth=len(guests)
deleted_guest=guests.pop()
print(deleted_guest)
guests.insert(2,deleted_guest)
guests.pop(1)
print(guests)
########## End ##########
第2关:列表元素的排序:给客人排序
# coding=utf-8
# 创建并初始化`source_list`列表
source_list = [] while True:
try:
list_element = input()
source_list.append(list_element)
except:
break
# 请在此添加代码,对source_list列表进行排序等操作并打印输出排序后的列表
########## Begin ##########
source_list.sort(reverse=False)
print(source_list)
########## End ##########
第3关:数值列表:用数字说话
# coding=utf-8
# 创建并读入range函数的相应参数
lower = int(input())
upper = int(input())
step = int(input())
# 请在此添加代码,实现编程要求
########## Begin ##########
sourse_list=list(range(lower,upper,step))
lenth=len(sourse_list)
print(lenth)
min_value=min(sourse_list)
max_value=max(sourse_list)
print(max_value-min_value)
########## End ##########
第4关:列表切片:你的菜单和我的菜单
# coding=utf-8
# 创建并初始化my_menu列表
my_menu = [] while True:
try:
food = input()
my_menu.append(food)
except:
break
# 请在此添加代码,对my_menu列表进行切片操作
########## Begin ##########
lenth=len(my_menu)
list_slice=my_menu[:lenth:3] print(list_slice)
list_slice2=my_menu[-3:] print(list_slice2)
########## End ##########
作者:.sunshine️