day05作业

1.一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)?

n=0
 while True:
    sum=(8e-5)*2**n
    if sum<8848.13:
        n+=1
    else:
        print(n)
        break
  1. 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
n=int(input('输入月份'))
 pre_2=0
 pre_1=1
 current=1
 for x in range(n-2):
    pre_2=pre_1
    pre_1=current
    current=pre_1+pre_2

 print('兔子总数为:',current)
  1. 将一个正整数分解质因数。例如:输入90,打印出90=2x3x3x5。
while 1:
     n = int(input('请输入一个整数:'))
     print('%d='%n,end='')
     while n>1:
         for i in range(2,n+1):
             if n%i==0:
                 n=int(n/i)
                 if n==1:
                     print('%d'%i,end='')
                 else:
                     print('%d*'%i,end='')
                 break
    print()
  1. 输入两个正整数m和n,求其最大公约数和最小公倍数。 程序分析:利用辗除法。
m = int(input('输入第一个正整数:'))
n = int(input('输入第二个正整数:'))
x = m
y = n  
if m < n:   
    temp = m
    m = n
    n = temp
c = m % n
while c != 0:
    m = n
    n = c 
    c = m % n
  1. 一个数如果恰好等于它的因子之和,这个数就称为 "完数 "。例如6=1+2+3. 编程 找出1000以内的所有完数
for i in range(2,1001):
    s=i
    for j in range(1,i):
        if i%j==0:
            s-=j
    if s==0:
        print(i)

6.输入某年某月某日,判断这一天是这一年的第几天? 程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。

year=int(input('输入年份:'))
month=int(input('输入月份:'))
day=int(input('输入日:'))
count=0
if month==1:
    count=day
elif month==2:
    count=31+day
elif month==3 and (year%4==0 and year%100!=0) or (year%400==0):
    count=31+29+day
elif month==4:
    count=31+29+31+day
elif month==5:
    count=31+29+31+30+day
elif month==6:
    count=31+29+31+30+31+day
elif month==7:
    count=31+29+31+30+31+30+day
elif month==8:
    count=31+29+31+30+31+30+31+day
elif month==9:
    count=31+29+31+30+31+30+31+31+day
elif month==10:
    count=31+29+31+30+31+30+31+31+30+day
elif month==11:
    count=31+29+31+30+31+30+31+31+30+31+day
elif month==12:
    count=31+29+31+30+31+30+31+31+30+31+30+day
else:
    if month==3:
        count=31+28+day

    if month==4:
        count=31+28+31+day
    if month==5:
        count=31+28+31+30+day
    if month==6:
        count=31+28+31+30+31+day
    if month==7:
        count=31+28+31+30+31+30+day
    if month==8:
        count=31+28+31+30+31+30+31+day
    if month==9:
        count=31+28+31+30+31+30+31+31+day
    if month==10:
        count=31+28+31+30+31+30+31+31+30+day
    if month==11:
        count=31+28+31+30+31+30+31+31+30+31+day
    if month==12:
        count=31+28+31+30+31+30+31+31+30+31+30+day
print('第',count,'天')
  1. 某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。求输入的四位整数加密后的值
n=int(input('输入一个四位数:'))
ge=n%10
shi=n//10%10
bai=n//100%10
qian=n//1000
print(ge,shi,bai,qian)
ge=(ge+5)%10
shi=(shi+5)%10
bai=(bai+5)%10
qian=(qian+5)%10
ge,shi,bai,qian=qian,bai,shi,ge
print(qian,bai,shi,ge)
  1. 获取第n个丑数。 什么是丑数: 因子只包含2,3,5的数
n = int (input('想要获取第几个丑数:'))
n1 = n
if n == 1:
    print('第1个丑数是1')
for i in range(2,1000):
    x = i
    while True:
        if i % 2 == 0:
            i = i // 2
        elif i % 3 == 0:
            i = i // 3
        elif i % 5 == 0:
            i = i // 5
        else:
            break

        if i == 1: # 是丑数
            n -=1
            break
    if n == 1:
        print('第%d个丑数是:%d' %(n1,x))
        break
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)? 2. 古典问题:有...
    刘茂森阅读 1,328评论 0 0
  • 1一张纸的厚度大约是0.08mm,对折多少次后能到达珠穆朗玛峰的高度(8838.13m) 2.古典问题:有一对兔子...
    PonesRyang阅读 1,121评论 0 0
  • 1. 一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)? 2. 古典问题...
    我去买个橘子o阅读 1,522评论 0 0
  • 第一题 请输入一个整数:>>>524690 第二题 请输入一个整数:>>>5@@@@@@@@@@@@@@@ 第三题...
    LPP27149阅读 1,531评论 0 5
  • 读程序,总结程序的功能: 求2的20次方 统计1~100中能被3整除或被7整除,但同时不能被21整除的数字的个数 ...
    挽风style阅读 1,589评论 0 0

友情链接更多精彩内容