Python基礎綜合練習

2022-06-04 05:57:07 字數 2338 閱讀 4923

畫一面五星紅旗,將**與執行截圖發布部落格交作業

import turtle

t = turtle.pen();

t.hideturtle()

#移動筆

def mygoto(x, y):

t.up()

t.goto(x, y)

t.down()

#畫五角星

def dramfive(x):

t.begin_fill()

for i in range(5):

t.forward(x);

t.right(144);

t.end_fill();

t.speed(5);

t.pensize(1);

#紅色國旗

t.color('red');

mygoto(-300,250)

t.begin_fill()

for i in range(2):

t.forward(600)

t.right(90)

t.forward(400)

t.right(90)

t.end_fill()

#大五角星

t.color('yellow');

mygoto(-260,180)

dramfive(120)

#小五角星

取得校園新聞的編號

str1 =""

print(str1[-9:-5])

產生python文件的**

str2 =""

print(str2.replace("turtle","python"))

產生校園新聞的一系列新聞頁**

area1 = ""

area2 = ".html"

for i in range(2,10):

area = area1 + str(i) + area2

str3 = "{}.html".format(i)

print(str3,area)

用函式得到校園新聞編號

str4 =""

print (str4.split('_',2)[1].rstrip(".html"))

用函式統計一歌詞(文章、**)中單詞出現的次數,替換標點符號為空格,用空格進行分詞。

str5 = '''you do the hokey pokey and you turn yourself around.

that‟s what it‟s all about.

you put your right foot in, you put your right foot out.

you put your right foot in, and you shake it all about.

you do the hokey pokey and you turn yourself around.

that‟s what it‟s all about.

you put your left foot in, you put your left foot out.

you put your left foot in, and you shake it all about.

you do the hokey pokey and you turn yourself around.

that‟s what it‟s all about.

you put your whole self in, you put your whole self out.

you put your whole self in, and you shake it all about.

you do the hokey pokey and you turn yourself around.

that‟s what it‟s all about.'''

print(str5.count("you"));

print(str5.replace("."," "))

print(str5.split())

Python基礎綜合練習

hey 下一秒向你靠近 夢已準備就緒 show you 我的心絕不放棄 i m the one you want 不需要遲疑 綻放所有光芒shining 只想為你證明 你整個世界被我佔據 i m the one you want絕無可代替 幸運的視角 都為我聚焦 你的每個決定是我渴望的驕傲 讓 猶豫...

python基礎 綜合小練習

在猜年齡的基礎上編寫登入 註冊方法,並且把猜年齡遊戲分函式處理,如 登入函式 註冊函式 猜年齡函式 選擇獎品函式 def register 註冊功能 count 0 while count 3 username inp input 請輸入你的使用者名稱 pwd inp input 請輸入你的密碼 r...

Pandas基礎 綜合練習 Python學習筆記

1 請刪除最後一列為缺失值的行,並求所有在杭州發貨的商品單價均值。2 商品標題帶有 嘉興 但發貨地卻不在嘉興的商品有多少條記錄?3 請按照分位數將 分為 高 較高 中 較低 低 5 個類別,再將 類別結果插入到標題一列之後,最後對類別列進行降序排序。4 付款人數一欄有缺失值嗎?若有則請利用上一問的分...