本文目錄一覽:
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中基礎練習題?
法一:利用set()函數的去重功能,去重後再使用list()函數將集合轉換為我們想要的列表
list1 = [11,22,33]
list2 = [22,33,44]
list3 = list(set(list1 + list2))
list3.sort()
print(list3)
————-
法二:利用if和for,先遍歷list1所有元素追加到list3中,然後遍歷list2,條件判斷list2中當前元素是否在list3中,如果不在則追加到list3中
list1 = [11,22,33]
list2 = [22,33,44]
list3 = []
for ele1 in list1:
list3.append(ele1)
for ele2 in list2:
if ele2 not in list3:
list3.append(ele2)
print(list3)
python練習題請教?
腳本從左向右執行:
ls[2] = [10, “LIST”]
ls[2][-1] = “LIST” 就是 [10, “LIST”][-1] 就是 “LIST”
ls[2][-1][1] 就是 “LIST”[1] 就是 “LIST” 的第二個字符,就是 I
所以 ls[2][-1][1] = “I”
python練習題
#!/usr/bin/env/python
# coding: utf-8
#
def fibonacci(n):
“””
This question is about Fibonacci number. For your information, the Fibonacci sequence is as follows:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, …
That is, the first two Fibonacci numbers are 0 and 1, each Fibonacci number after that is equal to the sum of the
two numbers that precede it. For example, the third Fibonacci number is equal to the sum of the first and
second number, the fourth number is equal to the sum of the second and third number, and so on …
Write a program that asks the user to enter a positive integer n, then your program should print/output in one
line the Fibonacci sequence up to n.
For example, if n is 100, your program should output 0,1,1,2,3,5,8,13,21,34,55,89,
If n is 8, your program should output 0,1,1,2,3,5,8,
“””
def __iter__(n):
a, b = 0, 1
yield a
if n == 0:
return
yield b
if n == 1:
return
while a + b = n:
a, b = b, a+b
yield b
return list(__iter__(n))
if __name__ == “__main__”:
print fibonacci(35)
關於python 語言基礎的練習題?
一、Python語言的簡述
Python語言是一種解釋型、面向對象的編程語言,是一種開源語言。
Python屬於動態類定義語言,也是一種強調類型語言。
二、Python語言的特點
1、簡單、高級
2、面向對象
3、可擴展性、免費和開源的
4、可移植型、可嵌入型、豐富的庫
三、Python語言的應用範圍
1、操作系統管理
2、科學計算
3、Web應用
4、圖形用戶界面(GUI)開發
5、其他,例如遊戲開發等
優點
簡單:Python是一種代表簡單主義思想的語言。閱讀一個良好的Python程序就感覺像是在讀英語一樣。它使你能夠專註於解決問題而不是去搞明白語言本身。
易學:Python極其容易上手,因為Python有極其簡單的說明文檔。
易讀、易維護:風格清晰劃一、強制縮進。
用途廣泛。
速度快:Python的底層是用C語言寫的,很多標準庫和第三方庫也都是用C寫的,運行速度非常快。
免費、開源:Python是FLOSS(自由/開放源碼軟件)之一。使用者可以自由地發佈這個軟件的拷貝、閱讀它的源代碼、對它做改動、把它的一部分用於新的自由軟件中。FLOSS是基於一個團體分享知識的概念。
python練習題怎麼做?
stds_list= [
{“id”: 1, “name”: “小明”, “c_s”: 85, “python_s”: 78},
{“id”: 2, “name”: “小花”, “c_s”: 69, “python_s”: 88},
{“id”: 3, “name”: “小東”, “c_s”: 79, “python_s”: 83},
]
# 1) 顯示學生信息:「學生id:學生姓名:小明,C語言成績:85, Python成績:78」。
for ind in range(len(stds_list)):
if stds_list[ind][‘name’] == ‘小明’:
print(‘學生id:{id},學生姓名:{name},C語言成績:{c_s}, Python成績:{python_s}’.format(**stds_list[ind]))
# 2) 修改「小明」的Python成績為90
for ind in range(len(stds_list)):
if stds_list[ind][‘name’] == ‘小明’:
stds_list[ind][‘python_s’] = 90
break
# 3) 刪除「小東」的信息
for ind in range(len(stds_list)):
if stds_list[ind][‘name’] == ‘小東’:
del stds_list[ind]
break
# 2. 定義一個空列表,用於保存5個學生信息,一個學生信息包括三個屬性:id、姓名、年齡
# 提示:列表元素是字典、向列表中添加數據用append()
stds_list2 = []
for i in range(5):
print(‘第{}個學生信息:’)
stds_list2.append({})
for j in [‘id’,’姓名’,’年齡’]:
stds_list2[-1][j] = input(‘{}:’.format(j))
print(stds_list2)
代碼縮進
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/275988.html