L1-015跟奥巴马一起画正方形(python3)
作者:互联网
思路:首先输入一个长度和一个符号,行是列的50%所以我们采用四舍五入,在遍历出符号就可以了
# 接收长和符号
length, symbol = input().split(' ')
length = int(length)
width = round(length/2,0) # 四舍五入
if 3 <= length <= 21:
for i in range(int(width)): # 循环列数的50%
print(symbol * length) # 字符*数字:表示重“数字”个“字符”
else:
exit(0)
但是出现了格式错误。
参考:https://blog.csdn.net/wtzszzx/article/details/119887406?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164223562816780357245581%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164223562816780357245581&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-4-119887406.first_rank_v2_pc_rank_v29&utm_term=L1-015+%E8%B7%9F%E5%A5%A5%E5%B7%B4%E9%A9%AC%E4%B8%80%E8%B5%B7%E7%94%BB%E6%96%B9%E5%9D%97+python&spm=1018.2226.3001.4187
写出:
代码:# 接收长和符号
length, symbol = input().split(' ')
# 转化为int类型
length = int(length)
# 四舍五入
width = length//2 + length % 2
# 如果正方形边长N(3≤N≤21),则开始循环
if 3 <= length <= 21:
# 循环列数的50%
for i in range(width):
# 字符*数字:表示重“数字”个“字符”
print(symbol * length)
else:
exit(0)
标签:四舍五入,E5%,2522%,rank,int,length,015,L1,python3 来源: https://blog.csdn.net/qq_53500156/article/details/122537315