- 1、python練習題求助
- 2、python練習題
- 3、Python中基礎練習題?
- 4、《python從入門到實踐》練習題有答案嗎
- 5、關於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)
#!/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)
法一:利用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)
找不到,只找到找到幾道題目的答案
8-9 魔術師:創建一個包含魔術師名字的列表,並將其傳遞給一個名為show_magicians() 的函數,這個函數列印列表中每個魔術師的名字。8-10 了不起的魔術師:在你為完成練習 8-9 而編寫的程序中,編寫一個名為make_great() 的函數,對魔術師列表進行修改,在每個魔術師的名字中都加入字樣「theGreat」。調用函數 show_magicians() ,確認魔術師列表確實變了。想問下大神怎麼對魔術師列表進行修改同時又不使用新的列表,我修改了一次但是用了一個新列表的方法和原習題不符。
一、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是基於一個團體分享知識的概念。
原創文章,作者:SC4JO,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/126833.html