正文
字符图形
import math
import sys
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
zreb = int(input())
mylist = []
for i in range(1, zreb):
mylist.append(i * "* ")
mylist = [item.rstrip() for item in mylist]
print(*mylist, sep="\n")
print((zreb * "* ").strip())
# mylist倒叙
print(*mylist[::-1], sep="\n")
来看一种更优雅的解法(作者:FrancoRoura)
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
asd = int(input())
for i in range(1,asd):
print(*["*"] * i)
for i in range(asd,0,-1):
print(*["*"] * i)
print(*["*"] * i)
这里注意["*"] * i这个是i数个列表,比如i=3就是["*"]["*"]["*"],然后左面的*解包为参数,相当于print(*,*,*),而print默认是中间空格(这样也是刚好解决了最后面空格的问题),所以刚好解决
快乐蛇
作者:ColibriTech
import sys
import math
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
h = 0
s = 0
n = int(input())
for i in range(n):
snake = input()
if "-<" in snake or ">-" in snake:
h += 1
else:
s += 1
print(f"{round(h/(h+s)*100)}%")
进度条
import math
import sys
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
chunks = int(input())
size = int(input())
print(
chunks * "#" + (size - chunks) * "." + " " + str(round(chunks / size * 100)) + "%"
)
写在最后
欢迎技术类的问题到这里提出,我会逐个解答