码迷,mamicode.com
首页 > 其他好文 > 详细

练习记录总结~

时间:2019-01-07 01:29:03      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:判断   冒泡   打印   +=   总结   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的正方形"""

n = int(input(>>>))
for i in range(n):
    if i==0 or i == (n-1):
        print(*  * n)
    else:      
        print(* +  * (n*2-3)+ *)

 


"""求100以内所有奇数的和(2500)"""

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)

 


 

"""求1到5的乘阶之和"""

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!