1.一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)?
paper_thickness = 0.08 / 1000
mountain = 8848.13
count = 0
while paper_thickness <= mountain:
paper_thickness *= 2
count += 1
print(count)
n = eval(input("输入第几个月:"))
sum1 = 0
num = 1
for _ in range(n):
sum2 = sum1 + num
num = sum1
sum1 = sum2
print("总的对数有:", sum2)
number = int(input("请输入数:"))
num = 2
list1 = []
str1 = ''
print("90=", end='')
while num <= number:
if number % num == 0:
number = number / num
list1.append(str(num))
else:
num += 1
str1 = '*'.join(list1)
print(str1)
m = int(input("请输入第一个整数m:"))
n = int(input("请输入第二个整数n:"))
remainder = 0
x = m * n
while n != 0:
remainder = m % n
m = n
n = remainder
print("最大公约数是:", m)
print("最小公倍数是:", int(x/m))
for x in range(2, 1000):
sum1 = 0
for y in range(1, x):
if x % y == 0:
sum1 += y
if sum1 == x:
print(x)
6.输入某年某月某日,判断这一天是这一年的第几天? 程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。
ear = int(input("年:"))
month1 = int(input("月:"))
day = int(input("日:"))
list1 = [1, 3, 5, 7, 8, 10, 12]
list2 = [4, 6, 9, 11]
list3 = [2]
add_day = 0
month = 1
while month < month1:
if month in list1:
day1 = 31
elif month in list2:
day1 = 30
elif month in list3 and (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
day1 = 29
else:
day1 = 28
day += day1
month += 1
print(day)
num = int(input("请输入四位数字:"))
list1 = []
x = 0
first_num = num // 1000 + 5
second_num = num // 100 % 10 + 5
three_num = num // 10 % 10 + 5
four_num = num % 10 + 5
x = first_num
first_num = four_num
four_num = x
x = second_num
second_num = three_num
three_num = x
list1.append(first_num)
list1.append(second_num)
list1.append(three_num)
list1.append(four_num)
a = [str(i) for i in list1]
b = "".join(a)
print("加密后的值为:", b)
获取第n个丑数。 什么是丑数: 因子只包含2,3,5的数
6 =1* 2*3 -> 丑数
2 = 1*2 -> 丑数
7 = 1*7 -> 不是丑数
1, 2, 3, 4, 5, 6, 8,9,10, 12 ….
n = int(input("获取第几个丑数:"))
list1 = [1]
for x in range(1, n):
for i in (2, 3, 5):
if x*i not in list1:
list1.append(x*i)
list1 = sorted(list1)
print("第n个丑数是:%d" % list1[n-1])