Excel如何設(shè)置動(dòng)態(tài)求和 Excel設(shè)置動(dòng)態(tài)求和方法
864
2025-03-31
編寫(xiě)一個(gè)計(jì)算天數(shù)的程序,用戶從鍵盤中輸入年、月、日,在屏幕中輸出此日期是該年的第幾天。
C代碼:
/*第三天、計(jì)算某日是該年的第幾天*/ #include
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
結(jié)果顯示:
python代碼,C代碼的升級(jí)版,可以進(jìn)行輸入判斷:
def leap(a): if (a % 4 == 0) & (a % 100 != 0) | (a % 400 == 0): return 1 else: return 0 def number(y,m,d): result = 0 average_year = (31,28,31,30,31,30,31,31,30,31,30,31) #平年的元組 leap_year = (31,29,31,30,31,30,31,31,30,31,30,31) #閏年的元組 if (1 <= y <= 5000) & (1 <= m <= 12) & (1 <= d <=31) & leap(y) & (d <= leap_year[m-1]): for i in range(0,m-1): result += leap_year[i] elif (1 <= y <= 5000) & (1 <= m <= 12) & (1 <= d <=31) & (leap(y) == 0) & (d <= average_year[m-1]): for i in range(0,m-1): result += average_year[i] else: result = 0 d = 0 result += d return result def tranform(contents): if ('年' in contents) & ('月'in contents) & ('日' in contents) & (' ' not in contents): str_len = len(contents) for i in range(1,str_len): if contents[i] == '年': year = int(contents[0:i]) #input()接收的是字符串 year_num = i + 1 if contents[i] == '月': month = int(contents[year_num:i]) #用int()強(qiáng)制轉(zhuǎn)換成整型 month_num = i + 1 if contents[i] == '日': day = int(contents[month_num:i]) return (year,month,day) else: return 0 choose = 1 while choose: contents = input('請(qǐng)輸入要查詢的日期,查詢范圍公元1年-公元5000年,例如:1993年1月30日\(chéng)n') t = tranform(contents) if t != 0: result = number(t[0],t[1],t[2]) if result != 0: print('第%d天' %(result)) while True: choose = input('輸入‘是’繼續(xù)查詢,輸入‘否’放棄查詢\n') if ('是' in choose) | ('否' in choose) & (len(choose) == 1): if '是' in choose: choose = 1 break else: choose = 0 break else: print('輸入選擇錯(cuò)誤,請(qǐng)重新輸入\n') else: print('輸入日期錯(cuò)誤,請(qǐng)重新輸入\n') else: print('輸入格式錯(cuò)誤,請(qǐng)重新輸入\n')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
結(jié)果顯示:
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。