赞
踩
python作业基础——第一节:
x = float(input('x = '))
if x > 1:
y = 3 * x - 5
elif x >= -1:
y = x + 2
else:
y = 5 * x + 3
print(f'f({x:.2f}) = {y:.2f}')
sum = 0
for x in range(2, 101, 2):
sum += x
print("1-100偶数求和:",sum)
在这里插入代码片
for i in range(1, 10):
for j in range(1, i + 1):
print('%d*%d=%d' % (j, i, i * j), end='\t')
print()
import math as m
num=int(input("请输入一个正整数:"))
end=int(m.sqrt(num))
is_prime=True
for i in range(2,end+1):
if num%i==0:
is_prime=False
break
if is_prime and num!=1:
print("%d 是素数"%num)
else:
print("%d 不是素数"%num)
for i in range(5): for j in range(i+1): print("*",end='') print() for i in range(1,6): for j in range(5-i): print(' ',end='') for k in range(i): print('*',end='') print() for i in range(1,6): for j in range(5-i): print(' ',end='') for k in range(2*i-1): print('*',end='') print()
y=int(input("请输入y:"))
if x>y:
x,y=y,x
value=1
for i in range(x,0,-1):
if x%i==0 and y%i==0:
print("%d 和 %d 的最大公约数:%d"%(x,y,i))
print("%d 和 %d 的最小公倍数:%d" % (x, y, x*y/i))
break
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。