日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第一章节测试

發布時間:2023/11/29 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第一章节测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大家在做第一章測試題時,需要復習如下相關知識點:編譯型VS解釋型、變量名規范、數據類型、程序交互、格式化輸出、運算符、流程控制。
1.簡述編譯型與解釋型語言的區別,且分別列出你知道的那些語言屬于編譯型,哪些屬于解釋型。
2.執行Python腳本的兩種方式是什么?
3.布爾值分別有什么?
4.如何查看變量在內存中的地址?
5.實現用戶輸入用戶名和密碼,當用戶名為seven且密碼為123時,顯示登錄成功,否則登錄失敗! 1 user = 'seven' 2 pwd = 123 3 username = input('username:') 4 password = int(input('password:')) 5 if username == user and password == pwd: 6 print('Welcome to %s' % username) 7 else: 8 print('Wrong username or password') View Code

6.實現用戶輸入用戶名和密碼,當用戶名為seven且密碼為123時,顯示登錄成功,否則登錄失敗,失敗時允許重復輸入三次。

1 user = 'seven' 2 pwd = 123 3 count = 0 # 計數器 4 while count < 3: 5 username = input('username:') 6 password = int(input('password:')) 7 if username == user and password == pwd: 8 print('Welcome to %s' % username) 9 break 10 else: 11 print('Wrong username or password') 12 count += 1 View Code

7.實現用戶輸入用戶名和密碼,當用戶名為seven或Alex且密碼為123時,顯示登錄成功,否則登錄失敗,失敗時允許重復輸入三次。

1 user = ['seven', 'alex'] 2 pwd = 123 3 count = 0 4 while count < 3: 5 username = input('username:') 6 password = int(input('password:')) 7 if username in user: 8 if password == pwd: 9 print('Welcome to %s' % username) 10 break 11 else: 12 print('Wrong username or password') 13 count += 1 View Code

8.聲明變量注意事項有哪些?

9.Python 單行注釋和多行注釋分別用什么?

10.編寫成績的小程序,成績有ABCDE5個等級,與分數的對應關系如下:

A  90-100
B  80-89
C  60-79
D  40-59
E  0-39
要求:用戶輸入0-100的數字后,你能正確打印它的對應成績 1 grade = int(input('please your grade:')) 2 if grade >= 100: 3 print('grade is 0-100') 4 elif 90 <= grade < 100: 5 print('A') 6 elif 80 <= grade < 89: 7 print('B') 8 elif 60 <= grade < 79: 9 print('C') 10 elif 40 <= grade < 59: 11 print('D') 12 else: 13 print('E') View Code

11.寫代碼

a.使用while循環實現輸出2-3+4-5+6...+100的和

1 count = 2 2 s = 0 3 while count <= 100: # loop 3 s = -1 count = 4 4 if count % 2 == 0: 5 s += count 6 else: 7 s -= count # 3 8 count += 1 9 print(s) View Code

b.使用while循環實現輸出1,2,3,4,5,8,9,11,12

1 count = 0 2 while count < 12: 3 count += 1 4 if count == 6: 5 continue 6 elif count == 10: 7 continue 8 print(count) View Code

c.使用while循環輸出100-50,從大到小,如100,99,98...,到50時,再從0循環輸出到50,然后結束。

小白方法:

1 count = 100 2 while count >= 50: 3 print(count) 4 count -= 1 5 count = 0 6 while count <= 50: 7 print(count) 8 count += 1 View Cod 高級玩法: 1 count = 0 2 while count <= 100: 3 count += 1 4 if count <= 50: 5 print(100 - count) # count = 1 6 else: 7 print(count - 51) # count =51 0 52 1 View Code

d. 使用while 循環實現輸出1-100內的所有奇數。

1 count = 0 2 while count < 100: 3 count += 1 4 if count % 2 != 0: 5 print(count) View Code

e.使用while循環實現輸出1-100內的所有偶數。

1 count = 0 2 while count < 100: 3 count += 1 4 if count % 2 == 0: 5 print(count) View Code

12.制作趣味模板程序(編程題)

 需求:等待用戶輸入名字、地點、愛好,根據用戶的名字和愛好任意顯示。

1 name = input("Name:").strip() 2 site = input("Site:").strip() 3 hobby = input("Hobby:").strip() 4 print("可愛的%s,最喜歡在%s看書。愛好是%s" % (name, site, hobby)) View Code

13.輸入年份,判斷該年份是否是閏年并輸出結果。(編程題)

 需求:凡符合下面兩個條件之一的年份就是閏年。(1)能被4整除但不能被100整除。(2)能被400整除。

1 while True: 2 year = int(input('Please is year:')) 3 if year % 4 == 0 and year % 100 != 0: 4 print("%s is leap year." % year) 5 break 6 elif year % 400 == 0: 7 exit("%s is a century" % year) 8 else: 9 exit("不是閏年") View Code

?14.假設一年定期利率為3.25%,計算一下要過多少年,一萬元的一年定期存款連本帶息能翻翻?(編程題)

1 # 利息計算的基本公式為:利息=本金×存期時間×存款利率; 2 capital = 10000 # 本金 3 count = 0 4 while capital< 20000: 5 count += 1 6 interest = capital * 0.0325 # 利息 7 capital += interest # 連本帶息 8 print(capital, count) View Code

15.使用while,完成以下圖形的輸出

*
**
***
****
*****
****
***
**
*

1 count = 0 2 while count < 10: 3 count += 1 4 if count <= 5: 5 print(count * '*') 6 else: 7 print((10-count) * '*') # count 6 View Code

16.使用while循環實現1-100的整數相加

1 count = 0 2 s = 0 3 while count < 100: 4 count += 1 5 s += count 6 print(s) View Code

17.一球從100米高度自由落下。每次落地后反跳回原高度的一半;在落下,求它在第10次落地時,共經過多少米?第10次反跳多高。

1 height = 100 2 count = 0 3 n = 100 4 while count < 10: 5 height = height / 2 # 反彈高度50, 6 n += height * 2 # 統計總長度 7 count += 1 8 print(count, height, n) View Code

?18.表達式for loop

最簡單的循環10次

1 for i in range(10): 2 print('loop', i) View Code

需求一:還是上面的程序,但是遇到小于5的循環次數就不走了,直接跳入下一次循環

1 for i in range(10): 2 if i < 5: 3 continue # 不往下走了,直接進入下一次loop 4 print('loop', i) View Code

需求二:還是上面的程序,但是遇到大于5的循環次數就不走了,直接退出

1 for i in range(10): 2 if i > 5: 3 break # 不往下走了,直接跳出整個loop 4 print('loop', i) View Code

?

轉載于:https://www.cnblogs.com/gaojiangtao/p/9863873.html

總結

以上是生活随笔為你收集整理的第一章节测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。