小白入門 python菜鳥100題(1 5)

2021-09-24 22:00:00 字數 1415 閱讀 9635

1#1,2,3,4,組成各不相同的三位數

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):

s = 100i+10j+k

print(s)

print(i, j, k)

2# 企業利潤

這個思想很重要,採用數軸的方式,而不是很蠢的用if else 語句來不斷的判斷

fund = int(input(「請輸入本月的利潤輸入:」))

profit = [1000000, 600000, 400000, 200000, 100000, 0]

percent =[0.01, 0.015, 0.03, 0.05, 0.075, 0.1]

r = 0

for i in range(6):

if fund>profit[i]:

*r=r+(fund-profit[i])percent[i]

fund = profit[i]

print®

3#找出完全平方數

演算法很重要,說明了詳細的推到過程

for i in range(1, 85):

if 168 % i == 0 and i % 2 == 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 = n*n - 100

print(x)

4# 判斷這一天是哪一天

monthlist = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]

youryear = int(input(「enter your year number:」))

yourmonth = int(input(「enter your month number:」))

yourday = int(input(「enter your day number:」))

cacul = 0

1# for i in range(yourmonth - 1):

1# cacul += monthlist[i]

cacul = monthlist[yourmonth-1] + yourday

leap = 0

if (youryear % 400 == 0) or ((youryear % 4 == 0) and (youryear % 100 != 0)):

leap = 1

if (leap == 1) and (yourmonth > 2):

cacul += 1

小白入門 python菜鳥100題(6 10)

6 斐波那契數列,關鍵在 a,b b,a b def fib n a 0 b 1 for i in range n a,b b,a b print a fib 12 7 輸出99乘數 for i in range 1,10 print for j in range 1,i 1 x ij print ...

小白入門 python菜鳥100題(11 15)

11 有一對兔子,從出生後第3個月起每個月都生一對兔子,小兔子長到第三個月後每個月又生一對兔子,假如兔子都不死,問每個月的兔子總數為多少?0 斐波那契數列 a 0 b 1 for i in range 42 a,b b,a b print a 12 判斷101 200之間有多少個素數,並輸出所有素數...

小白入門 python菜鳥100題(21 25)

21 猴子吃桃問題 x 1 for i in range 9,0,1 x x 1 2 print 第 i,天的pich有 x,個 22 兩個桌球隊進行比賽,各出 妙啊妙啊 for a in x y z for b in x y z for c in x y z if a b and b c and ...