跳转至

DAT-03 阅读任务解析

返回任务 · 正文

任务 1

输出:

'  api-prod  '
False

strip返回的字符串没有被使用,raw仍关联原始文本。lower返回转为小写的文本,不会去掉首尾空格,因此startswith返回False。可以把service的赋值改为service = raw.strip().lower():先清理,再对返回值转小写。修改后输出如下。

raw = "  API-PROD  "
service = raw.strip().lower()
print(repr(service))
print(service.startswith("api-"))
'api-prod'
True

依据:正文 3.1。

任务 2

输出:

repor
report

strip参数中的字符为点、x和t,它从两端连续剥除这些字符;右端的.txt被去掉后,report末尾的t也被去掉,留下repor。removesuffix只删除完整后缀一次,得到report,因此第二种符合需求。

依据:正文 3.2。

任务 3

输出:

12.5%
0.125
<class 'str'>

ratio仍是浮点数0.125;text是展示文本12.5%。继续计算使用ratio,不能把格式化文本当成原数值。格式化输出乘100并添加百分号,只是在表达比例。

依据:正文 4.2。

三份材料及修改变体均见KVM原始输出。