本文目錄一覽:
python練習題求助
chars=[chr(i+ord(‘a’)) for i in range(26)]
print(chars)
result=[]
index=0
count=0
order=1
while True:
if count==26:
break
if chars[index].isalpha():
if order%5==0:
result.append(chars[index])
chars[index]=’0′
count+=1
order+=1
index=(index+1)%26
print(result)
python習題,求幫助
這道題的核心是熟練運用dict()和字元串的操作方法。具體如下:
源代碼
如有幫助,請採納!!!
python練習題
首先range是reversedword在這裡你可以理解為python保留辭彙也就是說你給一個變數賦值時不能命名其為range因為你下載的python里已經有了range的用法和相關操作規則wiki中的定義為areservedword(alsoknownasareservedidentifier)i
笨辦法學python 26習題怎麼做
def break_words(stuff):
“””This function will break up words for us.”””
words = stuff.split(‘ ‘)
return words
def sort_words(words):
“””Sorts the words.”””
return sorted(words)
def print_first_word(words):
“””Prints the first word after popping it off.”””
word = words.poop(0)
print word
def print_last_word(words):
“””Prints the last word after popping it off.”””
word = words.pop(-1)
print word
def sort_sentence(sentence):
“””Takes in a full sentence and returns the sorted words.”””
words = break_words(sentence)
return sort_words(words)
def print_first_and_last(sentence):
“””Prints the first and last words of the sentence.”””
words = break_words(sentence)
print_first_word(words)
print_last_word(words)
def print_first_and_last_sorted(sentence):
“””Sorts the words then prints the first and last one.”””
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
print “Let’s practice everything.”
print ‘You\’d need to know \’bout escapes with \\ that do \n newlines and \t tabs.’
poem = “””
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explantion
\n\t\twhere there is none.
“””
print “————–“
print poem
print “————–“
five = 10 – 2 + 3 – 5
print “This should be five: %s” % five
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars, crates = secret_formula(start_point)
print “With a starting point of: %d” % start_point
print “We’d have %d jeans, %d jars, and %d crates.” % (beans, jars, crates)
start_point = start_point / 10
print “We can also do that this way:”
print “We’d have %d beans, %d jars, and %d crabapples.” % secret_formula(start_point)
sentence = “All god\tthings come to those who weight.”
words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)
print_first_word(words)
print_last_word(words)
print_first_word(sorted_words)
print_last_word(sorted_words)
sorted_words = ex25.sort_sentence(sentence)
print sorted_words
print_irst_and_last(sentence)
print_first_a_last_sorted(senence)
這是26題 修改正確後的代碼 就是該語法錯誤,運行的時候 帶上你的25題代碼(EX25.py)
40道python二級考試真題火爆互聯網,完整版答案解析為你保駕護航
1.以下關於程序設計語言的描述,錯誤的選項是:
A Python語言是一種腳本編程語言
B 彙編語言是直接操作計算機硬體的編程語言
C 程序設計語言經歷了機器語言、彙編語言、腳本語言三個階段
D 編譯和解釋的區別是一次性翻譯程序還是每次執行時都要翻譯程序
正確答案: C
2.表達式 1001 == 0x3e7 的結果是:
A false
B False
C true
D True
正確答案: B
3.以下選項,不是Python保留字的選項是:
A del
B pass
C not
D string
正確答案: D
4.表達式 eval(『500/10』) 的結果是:
A 『500/10』
B 500/10
C 50
D 50.0
正確答案: D
5.表達式 type(eval(『45』)) 的結果是:
A
B
C None
D
正確答案: D
6.表達式 pmod(20,3) 的結果是:
A 6, 2
B 6
C 2
D (6, 2)
正確答案: D
7.以下關於字元串類型的操作的描述,錯誤的是:
A str.replace(x,y)方法把字元串str中所有的x子串都替換成y
B 想把一個字元串str所有的字元都大寫,用str.upper()
C 想獲取字元串str的長度,用字元串處理函數 str.len()
D 設 x = 』aa』 ,則執行x*3的結果是『aaaaaa』
正確答案: C
8.設 str = 『python』,想把字元串的第一個字母大寫,其他字母還是小寫,正確的選項是:
A print(str[0].upper()+str[1:])
B print(str[1].upper()+str[-1:1])
C print(str[0].upper()+str[1:-1])
D print(str[1].upper()+str[2:])
正確答案: A
9.以下選項,不屬於程序流程圖基本元素的是:
A 循環框
B 連接點
C 判斷框
D 起始框
正確答案: A
10.以下關於循環結構的描述,錯誤的是:
A 遍歷循環使用for in 語句,其中循環結構不能是文件
B 使用range()函數可以指定for循環的次數
C for i in range(5)表示循環5次,i的值是從0到4
D 用字元串做循環結構的時候,循環的次數是字元串的長度
正確答案: A
11.執行以下程序,輸入」93python22」,輸出結果是:
A python9322
B python
C 93python22
D 9322
正確答案: C
A la
B 請輸入整數
C pythonpython
D python
正確答案: C
A 2
B 請輸入q退出:
C 3
D 1
正確答案: A
14.以下程序的輸出結果是:
A 0
B 2
C UnboundLocalError
D 5
正確答案: A
A 18 None
B 10 18
C UnboundLocalError
D 18 18
正確答案: B
def test( b = 2, a = 4):
global z
z += a * b
return z
z = 10
print(test(),z)
18,18
17.以下程序的輸出結果是:
A 22.0 None
B 10 None
C 22 None
D 10.0 22.0
正確答案: B
18.以下表達式,正確定義了一個集合數據對象的是:
A x = { 200, 』flg』, 20.3}
B x = ( 200, 』flg』, 20.3)
C x = [ 200, 』flg』, 20.3 ]
D x = {『flg』 : 20.3}
正確答案: A
19.以下程序的輸出結果是:
A [『z』, 『j』, 『s』, 『y』]
B [『j』, 『s』, 『y』, 『z』]
C [『j』, 『z』, 『z』, 『s』, 『z』, 『y』, 『j』]
D [『j』, 『j』, 『s』, 『y』, 『z』, 『z』, 『z』]
正確答案: B
20.以下程序的輸出結果是:
A htslbht
B hlbst
C tsblh
D hhlstt
正確答案: B
21.已知id(ls1) = 4404896968,以下程序的輸出結果是:
A 4404896968 4404896904
B 4404896904 4404896968
C 4404896968 4404896968
D 4404896904 4404896904
正確答案: A
A [『300』,『200』,『400』]
B [『shandong』, 『hebei』, 『beijing』]
C [300,200,400]
D 『shandong』, 『hebei』, 『beijing』
正確答案: B
23.以下關於文件的描述,錯誤的是:
A 二進位文件和文本文件的操作步驟都是「打開-操作-關閉」
B open() 打開文件之後,文件的內容並沒有在內存中
C open()只能打開一個已經存在的文件
D 文件讀寫之後,要調用close()才能確保文件被保存在磁碟中了
正確答案: C
24.以下程序輸出到文件text.csv里的結果是:
A [90,87,93]
B 90,87,93
C 『[90,87,93]』
D 『90,87,93』
正確答案: B
25.以下程序的輸出結果是:
A ( [1,2,3,4,5])
B [12, 34, 56, 78]
C ([12, 34, 56, 78])
D [1,2,3,4,5]
正確答案: B
26.以下關於數據維度的描述,錯誤的是:
A 採用列表表示一維數據,不同數據類型的元素是可以的
B JSON格式可以表示比二維數據還複雜的高維數據
C 二維數據可以看成是一維數據的組合形式
D 字典不可以表示二維以上的高維數據
正確答案: D
27.以下不屬於Python的pip工具命令的選項是:
A show
B install
C download
D get
正確答案: D
29.以下不是程序輸出結果的選項是:
A [12, 78, 56, 34]
B [56, 12, 78, 34]
C [12, 34, 56, 78]
D [12, 78, 34, 56]
正確答案: C
30.以下關於turtle庫的描述,正確的是:
A 在import turtle之後就可以用circle()語句,來畫一個圓圈
B 要用from turtle import turtle來導入所有的庫函數
C home() 函數設置當前畫筆位置到原點,朝向東
D seth(x) 是setheading(x)函數的別名,讓畫筆向前移動x
正確答案: C
31.一些重要的程序語言(如C語言和Pascal語言)允許過程的遞歸調用。而實現遞歸調用中的存儲分配通常用
A 棧
B 堆
C 鏈表
D 數組
正確答案: A
因為函數調用是能過將關鍵寄存器壓棧保護現場;在函數返回時,彈棧恢復現場來完成的。
而遞歸調用說白了就是自已調用自己。也就是不停的上演pop, push的棧操作。
系統為什麼選用棧來實現函數間的調用呢?我覺的主要原因如下:
對於頻繁的調用操作過程中,棧的pop,push操作最簡潔,快速。硬體級(或者理解成彙編級也行)支持棧操作。所以用棧最高效,快速。如果用堆、數組、鏈表,不光要維護很多功能輔助性數據,演算法也很麻煩。這樣會大大降低計算機的使用效率。
32.下列敘述中正確的是
A 一個演算法的空間複雜度大,則其時間複雜度必定小
B 一個演算法的空間複雜度大,則其時間複雜度也必定大
C 演算法的時間複雜度與空間複雜度沒有直接關係
D 一個演算法的時間複雜度大,則其空間複雜度必定小
正確答案: C
34.軟體開發離不開系統環境資源的支持,其中必要的測試數據屬於
A 輔助資源
B 硬體資源
C 通信資源
D 支持軟體
正確答案: A
35.完全不考慮程序的內部結構和內部特徵,而只是根據程序功能導出測試用例的測試方法是
A 錯誤推測法
B 白箱測試法
C 黑箱測試法
D 安裝測試法
正確答案: C
37.下列有關資料庫的描述,正確的是
A 資料庫是一個關係
B 資料庫是一個DBF文件
C 資料庫是一個結構化的數據集合
D 資料庫是一組文件
正確答案: C
38.相對於資料庫系統,文件系統的主要缺陷有數據關聯差、數據不一致性和
A 可重用性差
B 冗餘性
C 非持久性
D 安全性差
正確答案: B
39.軟體開發的結構化生命周期方法將軟體生命周期劃分成
A 定義、開發、運行維護
B 設計階段、編程階段、測試階段
C 總體設計、詳細設計、編程調試
D 需求分析、功能定義、系統設計
正確答案: A
40.下列不屬於結構化分析的常用工具的是
A 判定樹
B 數據字典
C 數據流圖
D PAD圖
正確答案: C
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/151699.html