第1关:字符串的拼接:名字的组成
任务描述
本关任务:将两个不同的字符串,拼接形成一个字符串,并将新字符输出来。
编程要求
本关的编程任务是,补全src/Step1/full_name.py文件中 Begin-End 区间的代码,实现如下功能:
将存放姓氏的字符串变量和存放名字的字符串变量拼接起来,中间用一个空格隔开,并将结果存储在full_name变量中;
打印输出full_name变量。
测试输入:
Hu
dong
预期输出:
Hu dong
#coding=utf-8
first_name = input()
last_name = input()
full_name = first_name + " " + last_name
print(full_name)
第2关:字符转换
任务描述
本关任务:对给定的字符串进行处理,包括字符串长度计算、大小写转换以及去除字符串前后空格等。
编程要求
本关的编程任务是,补全src/Step2/method1.py文件中 Begin-End 区间的代码,实现给定字符串的转换功能,具体要求如下:
step1 :将输入的源字符串 source_string 首尾的空格删除;
step2 :将 step1 处理后的字符串的所有单词的首字母变为大写,并打印输出;
step3 :将 step2 转换后的字符串的长度打印输出出来。
测试输入:
Where there is a will,there is a way
预期输出:
Where There Is A Will,There Is A Way
36
#coding=utf-8
source_string = input()
blank_source_string =source_string.strip()
title_source_string =blank_source_string.title()
print(title_source_string)
length=len(title_source_string)
print(length)
第3关:字符串查找与替换
任务描述
本关的任务:给定一个字符串,要利用 Python 提供的字符串处理方法,从该字符串中,查找特定的词汇,并将其替换为另外一个更合适的词。
编程要求
本关的编程任务是,补全src/Step3/method2.py文件中 Begin-End 区间的代码,实现如下功能:
step1 :查找输入字符串 source_string 中,是否存在 day 这个子字符串,并打印输出查找结果;
step2 :对输入字符串 source_string 执行字符替换操作,将其中所有的 day 替换为 time,并打印输出替换后的字符串;
step3 :对 step2 进行替换操作后的新字符串,按照空格进行分割,并将分割后的字符列表打印输出出来。
测试输入:
All day is no day when it is past.
预期输出:
1.4
2.All time is no time when it is past.
3.[‘All’, ‘time’, ‘is’, ‘no’, ‘time’, ‘when’, ‘it’, ‘is’, ‘past.’]
# coding = utf-8
source_string = input()
print(source_string.find('day'))
print(source_string.replace('day','time'))
split_source_string=source_string.replace('day','time')
print(split_source_string.split(' '))
······通关成功······
如有问题,敬请斧正。