1、有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
count = 0
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i!=j and i!=k and j!=k:
count = count + 1
print(i,j,k)
print(f"能组成{count}个互不相同且无重复数字的三位数")
2、一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
1)for i in range(1,85):
if 168 % i == 0:
j = 168 / i;
if i > j and (i + j) % 2 == 0 and (i - j) % 2 == 0 :
m = (i + j) / 2
n = (i - j) / 2
x = int(n * n - 100)
print(x)
2)
for i in range(-100,10000):
# 如果一个数开方为一个整数
if math.sqrt(i+100) == int(math.sqrt(i+100)) and math.sqrt(i+100+168) == int(math.sqrt(i+100+168)):
print(i)
3、输入某年某月某日,判断这一天是这一年的第几天?
year = int(input("year:"))
month = int(input("month:"))
day = int(input("day:"))
months=(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334)
if 0 < month <= 12:
sum =months[month - 1]
else:
print("月份输入错误!!!!")
sum += day
flag = 0
if(year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
flag = 1
if (flag == 1 ) and ( month>2 ):
sum += 1
print(f"输入{year}年{month}月{day}日,这一天是这{year}年的第{sum}天")
4、输入三个整数x,y,z,请把这三个数由小到大输出。
list = []
for i in range(3):
x = int(input(f'请输入第{i+1}个数:\n'))
list.append(x)
list.sort()
print (list)
5、斐波那契数列 (Fibonacci sequence),又称黄金分割数列,0、1、1、2、3、5、8、13、21、34、……。
def fib(n):
if n == 1 or n == 2:
return 1
return fib(n - 1) + fib(n - 2)
# 输出第10个斐波那契数列
print(fib(10))
def fib(n):
if n == 1:
return [1]
if n == 2:
return [1, 1]
fibs = [1, 1]
for i in range(2, n):
fibs.append(fibs[-1] + fibs[-2])
return fibs
# 输出前 10 个斐波那契数列
print(fib(10))
标签:练练,没事,month,int,range,year,print,100 From: https://www.cnblogs.com/liyongmei/p/16888044.html