给定一个五位数,求输出每一位数字
for循环写法
num = int(input("enter a number: "))
for i in range(5):
baseline = 10**(4-i)
x = num // baseline
print(x)
num = num - (x * baseline)
while循环写法
num = int(input("enter a number: "))
baseline = 10000
while baseline:
x = num // baseline
print(x)
num = num - (x * baseline)
baseline //= 10
打印N边长的正方形:
n = 5
for i in range(n):
if n == 1:
break
elif i == n-1 or i == 0:
print("*" * n)
else:
print("*" + " "*(n-2) + "*")
求指定范围以内的质数
n = 100
for i in range(3, n, 2):
for j in range(3, i):
if i % j == 0:
break
else:
print(i)
文档更新时间: 2020-04-04 15:37 作者:闻骏