标签:err 闰年 ota open 当前时间 小兔子 组成 inpu 比较
程序源代码:
1 for i in range(1, 5): 2 for j in range(1, 5): 3 for k in range(1, 5): 4 if (i != k) and (i != j) and (j != k): 5 print(i, j, k)
以上实例输出结果为:
1 1 2 3 2 1 2 4 3 1 3 2 4 1 3 4 5 1 4 2 6 1 4 3 7 2 1 3 8 2 1 4 9 2 3 1 10 2 3 4 11 2 4 1 12 2 4 3 13 3 1 2 14 3 1 4 15 3 2 1 16 3 2 4 17 3 4 1 18 3 4 2 19 4 1 2 20 4 1 3 21 4 2 1 22 4 2 3 23 4 3 1 24 4 3 2
程序源代码:
1 i = int(input(‘净利润:‘)) 2 arr = [1000000,600000,400000,200000,100000,0] 3 rat = [0.01,0.015,0.03,0.05,0.075,0.1] 4 r = 0 5 for idx in range(0,6): 6 if i>arr[idx]: 7 r+=(i-arr[idx])*rat[idx] 8 print ((i-arr[idx])*rat[idx]) 9 i=arr[idx] 10 print(r)
以上实例输出结果为:
1 净利润:120000 2 1500.0 3 10000.0 4 11500.0
程序源代码:
1 for i in range(1,85): 2 if 168 % i == 0: 3 j = 168 / i; 4 if i > j and (i + j) % 2 == 0 and (i - j) % 2 == 0 : 5 m = (i + j) / 2 6 n = (i - j) / 2 7 x = n * n - 100 8 print(x)
以上实例输出结果为:
1 -99.0 2 21.0 3 261.0 4 1581.0
程序源代码:
1 year = int(input(‘year:\n‘)) 2 month = int(input(‘month:\n‘)) 3 day = int(input(‘day:\n‘)) 4 5 months = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334) 6 if 0 < month <= 12: 7 sum = months[month - 1] 8 else: 9 print(‘data error‘) 10 sum += day 11 leap = 0 12 if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)): 13 leap = 1 14 if (leap == 1) and (month > 2): 15 sum += 1 16 print(‘It is the %dth day in the year.‘ % sum)
以上实例输出结果为:
1 year: 2 2018 3 month: 4 3 5 day: 6 23 7 It is the 82th day in the year
程序源代码:
1 l = [] 2 for i in range(3): 3 x = int(input(‘Please input sorted number:\n‘)) 4 l.append(x) 5 l.sort() 6 print(l)
以上实例输出结果为:
1 Please input sorted number: 2 1 3 Please input sorted number: 4 20 5 Please input sorted number: 6 5 7 [1, 5, 20]
程序源代码:
方式一:
1 def fib(n): 2 a, b = 1, 1 3 for i in range(n - 1): 4 a, b = b, a + b 5 return a 6 7 8 # 输出了第10个斐波那契数列 9 print(fib(10))
方式二:
1 # 使用递归 2 def fib(n): 3 if n == 1 or n == 2: 4 return 1 5 return fib(n - 1) + fib(n - 2) 6 7 8 # 输出了第10个斐波那契数列 9 print(fib(10))
以上实例输出结果均为:
1 55
方式三:
1 def fib(n): 2 if n == 1: 3 return [1] 4 if n == 2: 5 return [1, 1] 6 fibs = [1, 1] 7 for i in range(2, n): 8 fibs.append(fibs[-1] + fibs[-2]) 9 return fibs 10 11 # 输出前 10 个斐波那契数列 12 print(fib(10))
以上实例输出结果为:
1 [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
程序源代码:
1 a = [1, 2, 3] 2 b = a[:] 3 print (b)
以上实例输出结果为:
1 [1, 2, 3]
程序源代码:
1 for i in range(1, 10): 2 for j in range(1, i + 1): 3 mul = i * j; 4 if mul < 10: 5 print(str(j) + "x" + str(i) + "=" + str(mul), end=" "); 6 else: 7 print(str(j) + "x" + str(i) + "=" + str(mul), end=" "); 8 print();
以上实例输出结果为:
1 1x1=1 2 1x2=2 2x2=4 3 1x3=3 2x3=6 3x3=9 4 1x4=4 2x4=8 3x4=12 4x4=16 5 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 6 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 7 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 8 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 9 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
程序源代码:
1 import time 2 3 num_list = [1, 2, 3, 4, 5, 6] 4 for i in num_list: 5 print(i) 6 time.sleep(1) # 暂停 1 秒
以上实例输出结果为:
1 1 2 #暂停1秒 3 2 4 #暂停1秒 5 3 6 #暂停1秒 7 4 8 #暂停1秒 9 5 10 #暂停1秒 11 6
程序源代码:
1 import time 2 3 print(time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time()))) 4 5 # 暂停一秒 6 time.sleep(1) 7 8 print(time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime(time.time())))
以上实例输出结果为:
1 2019-03-23 11:16:07 2 #暂停1秒 3 2019-03-23 11:16:08
程序源代码:
1 f1 = 1 2 f2 = 1 3 for i in range(1, 22): 4 print(‘%d %d‘ % (f1, f2)) 5 if (i % 3) == 0: 6 print() 7 f1 = f1 + f2 8 f2 = f1 + f2
以上实例输出结果为:
1 1 1 2 2 3 3 5 8 4 5 13 21 6 34 55 7 89 144 8 9 233 377 10 610 987 11 1597 2584 12 13 4181 6765 14 10946 17711 15 28657 46368 16 17 75025 121393 18 196418 317811 19 514229 832040 20 21 1346269 2178309 22 3524578 5702887 23 9227465 14930352 24 25 24157817 39088169 26 63245986 102334155 27 165580141 267914296
程序源代码:
1 h = 0 2 leap = 1 3 from math import sqrt 4 from sys import stdout 5 6 for m in range(101, 201): 7 k = int(sqrt(m + 1)) 8 for i in range(2, k + 1): 9 if m % i == 0: 10 leap = 0 11 break 12 if leap == 1: 13 print(‘%-4d‘ % m) 14 h += 1 15 if h % 10 == 0: 16 print() 17 leap = 1 18 print(‘The total is %d‘ % h)
以上实例输出结果为:
1 101 2 103 3 107 4 109 5 113 6 127 7 131 8 137 9 139 10 149 11 12 151 13 157 14 163 15 167 16 173 17 179 18 181 19 191 20 193 21 197 22 23 199 24 The total is 21
程序源代码:
1 for n in range(100, 1000): 2 i = n // 100 3 j = n // 10 % 10 4 k = n % 10 5 if n == i ** 3 + j ** 3 + k ** 3: 6 print(n)
以上实例输出结果为:
1 153 2 370 3 371 4 407
程序源代码:
标签:err 闰年 ota open 当前时间 小兔子 组成 inpu 比较
原文地址:https://www.cnblogs.com/sun-10387834/p/10583156.html