注意,根据2018版本二级python考试要求,考试环境为Windows7 & python3.5 & python自带IDLE
参考答案:
我的解法:
# 请在______处使用一行代码或表达式替换
# 注意:请不要修改其他已给出代码
s = input("请输入一个字符串:")
print("{0:*^30}".format(s))
其中核心是理解format的用法
在Python 简明教程的format 方法讲解有举例
核心是理解
a=5
b=6
c=7
print('first is {1} ,second is {0} ,third is {2}'.format(a,b,c))
print('first is {0} ,second is {1} ,third is {2}'.format(a,b,c))
'''
输出
first is 6 ,second is 5 ,third is 7
first is 5 ,second is 6 ,third is 7
'''
上面是为了理解print({0:*^30}.format(s))
中0与s的对应关系
a='hello'
b='world'
c='$$$'
print("{0:*^30}".format(a,b,c))
print("{2:*^30}".format(a,b,c))
print("{1:!^30}".format(a,b,c))
print("{2:^^30}".format(a,b,c))
print("{2:^^10}".format(a,b,c))
'''
输出
************hello*************
*************$$$**************
!!!!!!!!!!!!world!!!!!!!!!!!!!
^^^^^^^^^^^^^$$$^^^^^^^^^^^^^^
^^^$$$^^^^
'''
看上面的代码就能理解这道题怎么做了