#求圆的面积(area)和周长(girth)import math
radius =int(input('Please input radius:'))
area = math.pi * radius **2
girth =2* math.pi * radius
print('area is ',area)print('girth is ',girth)
# 两个数比较大小,并且升序输出
num1 =int(input('Please input first number:'))
num2 =int(input('Please input second number'))if num1 > num2:print(num2,num1)else:print(num1,num2)
#依次输出n个数字,并输出最大数whileTrue:
num1 =input('Please input first number:')ifnot num1:break
num2 =input('Please inpuut second nubmer:')ifnot num2:break
num3 =input('Please input third number')ifnot num3:break
num1 =int(num1)
num2 =int(num2)
num3 =int(num3)if num1 > num2 and num1 > num3:print(num1)if num2 > num3 and num2 > num3:print(num2)if num3 > num2 and num3 > num1:print(num3)
# 输入n个数,并且打印输入后的算数平均数
count =0
summation =0whileTrue:
num =input('Please input a number:')ifnot num:print('NoneError')break
num =int(num)
count +=1
summation += num
average = summation / count
print(average)
# 打印一个正方形
side =int(input('Please input the side of a square:'))#方法一# print(side * "*")# for _ in range(side-2):# print('*' + (side - 2) * ' ' + '*')# print(side * "*")#方法二# for i in range(0,side):# if i % (side-1) == 0:# print(side * '*')# else:# print('*' + (side-2) * ' ' + '*')#方法三if side %2==0:
space =(side -1)*' 'else:
space =(side -2)*" "
axis = side //2for i inrange(-axis,axis+1):for j inrange(-axis,axis+1):ifabs(i)== axis or j ==-axis:print('*',end='')elif j == axis:print(space +'*',end='')print()
# 求100以内的奇数之和
summation =0
count =0for i inrange(1,100,2):
summation += i
print(summation)
# 求阶乘之和
num =int(input('>>>'))
sub =1
summation =0for i inrange(1,num+1):
sub *= i
summation += sub
print(summation)
# 判断一个数是否是素数
num =int(input('Please input a nubmer:'))
count =0if num ==2:print(num)
count =1elif num %2==0:print(num,'not\'s prime number')
count =1else:for i inrange(3,num,2):if num % i ==0:print(num,'not\'s prime number')break
count +=1else:print(num,'is prime number')print(count)
# 九九乘法表for i inrange(1,10):for j inrange(1,10):if j > i:passelse:
product = i * j
if j ==2and product <10:
tail =' 'else:
tail =' 'print(str(j)+"*"+str(i)+"="+str(product)+ tail,end='')print()
# 棱形
num =int(input('Please input a number:'))# 方法一:# axis = num // 2# for i in range(-axis,axis+1):# print(abs(i) * " " + (num - 2 * abs(i)) * "*")#方法二:
axis = num //2for i inrange(-axis,axis+1):print(abs(i)*" ",end='')for j inrange(-axis,axis+1):ifabs(i)+abs(j)<4:print('*',end='')print()
# 求100000以内的所有素数print(2)
count =1#方法一# for i in range(3,1000,2):# for j in range(2,i//2+1):# if i % j == 0:# break# else:# count += 1# print(i,end=' ')# print()# print('The numbers of prime number is :',count)
lst =[2]
count =1for i inrange(3,1000,2):# 从2开始到自身开平方的数找一个能整除的for j in lst:if i % j ==0:breakelse:
lst.append(i)
count +=1print('The numbers of prime number is:',count)print(lst)
#计算杨辉三角前6行
tmp_lst =[1]
lst =[]for i inrange(1,7):
lst.append(tmp_lst * i)for i inrange(1,5):for j inrange(i):
lst[i+1][j+1]= lst[i][j]+ lst[i][j+1]print(lst)