标签:判断 冒泡 打印 += 总结 sum == tin format
pi = 3.14 radii = int(input(‘>>>‘)) print(‘周长:‘,2 * pi * radii) print(‘面积:‘,(pi * radii)**2)
first = int(input(‘>>>‘)) second = int(input(‘>>>‘)) if first < second: print(first,second) else: print(second,first)
number = 0 while True: numbers = input(‘>>>‘) if numbers: numbers = int(numbers) if numbers > number: number = numbers else: break print(number)
count = 0 num = 0 while True: number = input(‘>>>‘) if number: num += int(number) count +=1 print(num / count) else: break
n = int(input(‘>>>‘)) for i in range(n): if i==0 or i == (n-1): print(‘* ‘ * n) else: print(‘*‘ + ‘ ‘* (n*2-3)+ ‘*‘)
num = 0 for i in range(1,100,2): num += i print(num)
num = int(input(‘>>>‘)) if num >= 80: if num >=90: print(‘A‘) else: print(‘B‘) else: if num >= 70: print(‘C‘) elif num >= 60: print(‘D‘) else: print(‘E‘)
num = 1 sum = 0 # for i in range(1,2): for j in range(1,6): num *= j sum += num print(sum) print(‘--------------‘)
n = int(input(">>>")) for i in range(2,n): if n % i == 0: print(‘不是‘) break else: print(‘是‘) break
for i in range(1,10): for j in range(1,i+1): print(str(j) + ‘ * ‘+ str(i),‘=‘,j*i,end=‘\t‘) print()
for i in range(-3,4): if i <= 0: print(‘ ‘ * -i +‘*‘ * (7+i*2)) # 1 3 5 7 5 3 1 else: #3 -2 -1 0 1 2 3 print(‘ ‘ * i + ‘*‘ * (7-i*2)) #4 5 6 7 6 5 4
"""打印100以内的斐波那契数列"""
a = 0 b = 1 for i in range(101): c = a + b a,b = b,c print(a)
"""输入三个数,用if判断大小"""
a = input(‘>>>‘) b = input(‘>>>‘) c = input(‘>>>‘) if a > b: if b > c: print(a,b,c) else: #c > b if a > c: print(a,c,b) else: print(c,a,b) else: if a > c: print(b,a,c) else: if b > c: print(b,c,a) else: print(c,b,a)
nums = [3,5,7,9,8,2,1,4,6] length = len(nums) for i in range(length - 1): flag = False for j in range(length -i -1): if nums[j] > nums[j+1]: nums[j], nums[j+1] = nums[j+1],nums[j] flag = True if not flag: break print(nums)
"""九九乘法表"""
for i in range(1,10): line = ‘‘ for j in range(1,i+1): line += ‘{} * {} = {:<{}}‘.format(j,i,i*j) print(line)
for i in range(1,10): for j in range(1,i+1): print(‘{} * {} = {:<{}}‘.format(j,i,i*j,5 if j == 1 else 6),end= ‘\n‘ if i == j else ‘‘)
for i in range(1,10): line = ‘‘ for j in range(i,10): line += (‘{} * {} = {:<3} ‘.format(i,j,i*j)) print(‘{:>110}‘.format(line))
for i in range(1,10): line = ‘‘ print(‘\n‘ + ‘\t‘* (i-1),end=‘‘) for j in range(i,10): print(‘{}*{}={}\t‘.format(j,i,i*j),end=‘‘)
"""对顶三角形""" for i in range(-3,4): print(‘ ‘* (3-abs(i)) + (abs(i)*2+1) * ‘*‘)
"""打印闪电"""
n = 7 e = 7 // 2 for i in range(-e,e+1): if i < 0: print(‘ ‘* (-i) + (4 + i) * ‘*‘) elif i == 0: print(‘*‘ * n) else: print(‘ ‘ * e + (4-i)*‘*‘)
"""猴子吃桃问题"""
a = 1 for i in range(9): a = (a+1)*2 print(a)
"""求十万以内的素数"""
import datetime count = 1 start = datetime.datetime.now() for i in range(3,100000,2): if i > 5 and i % 5 == 0: continue for j in range(3,int(i**0.5+1),2): if i % j== 0: break else: #print(i) count += 1 delta = (datetime.datetime.now()-start).total_seconds() print(delta,count)
# """杨辉三角""" nums = [[1],[1,1]] for i in range(1,5): nums.append([1]) for j in range(i): nums[i+1].append(nums[i][j] + nums[i][j+1]) nums[i+1].append(1) print(nums)
标签:判断 冒泡 打印 += 总结 sum == tin format
原文地址:https://www.cnblogs.com/Spiri-HGQ/p/10231086.html