Python基礎綜合練習

Pycharm開發環境設置與熟悉。

?

練習基本輸入輸出:

print('你好,{}.'.format(name))

print(sys.argv)

?

庫的使用方法:

import ...

from ... import ...

?

條件語句:

??? if (abs(pos()))<1:

??????? break

?

循環語句:

for i in range(5):

while True:

?

函數定義:

def mygoto(x,y):

def drawjx(r):

?

綜合練習:畫一面五星紅旗,將代碼與運行截圖發布博客交作業。

?

import turtledef mygoto(x, y):turtle.up()turtle.goto(x, y)turtle.down()def drawstar(x):turtle.begin_fill()for i in range(5):turtle.forward(x)turtle.right(144)turtle.end_fill()turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor("yellow")mygoto(-240, 90)
drawstar(100)mygoto(-100, 120)
turtle.left(50)
drawstar(30)mygoto(-50, 85)
turtle.left(-10)
drawstar(30)mygoto(-50, 45)
turtle.left(-40)
drawstar(30)mygoto(-100,10)
turtle.left(-20)
drawstar(30)turtle.hideturtle()
turtle.done()

  

?

字符串練習:

http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

取得校園新聞的編號

?

>>> url1 = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
>>> url1[-14:-5]

  

https://docs.python.org/3/library/turtle.html

產生python文檔的網址

?

>>> addr1 = 'https://docs.python.org/3/library/'
>>> addr2 = '.html'
>>> print(addr1 + 'turtle' + addr2)

  

http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

產生校園新聞的一系列新聞頁網址

?

>>> addr1 = 'http://news.gzcc.cn/html/xiaoyuanxinwen/'
>>> addr2 = '.html'
>>> for i in range(2,10):print(addr1 + str(i) + addr2)

  

練習字符串內建函數:strip,lstrip,rstrip,split,count,replace

用函數得到校園新聞編號

>>> url = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
>>> print(url.rstrip('.html').split('_')[1])

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

?

>>> song = '''
Camila Cabello、Young Thug - Havana
Pharrell Williams:Hey
Camila Cabello & Pharrell Williams:Havana ooh nana ayy
Half of my heart is in Havana oohnana ayy ayy
He took me back to East Atlanta nanana
All of my heart is in Havana ayy
There's somethin' 'bout his manners uh huh
Havana ooh nana
Camila Cabello:He didn't walk up with that how you doin'
When he came in the room
He said there's a lot of girls I can do with
But I can't without you
I'm doin' forever in a minute
That summer night in June
And papa says he got malo in him
He got me feelin' like
Ooohooohooh I knew it when I met him
I loved him when I left him
Got me feelin' like
Ooohooohooh and then I had to tell him
I had to go oh nanananana
Camila Cabello & Pharrell Williams:Havana ooh nana ayy
Half of my heart is in Havana oohnana ayy ayy
He took me back to East Atlanta nanana
All of my heart is in Havana ayy
My heart is in Havana
Havana ooh nana
Young Thug:Jeffery
Just graduated fresh on campus mmm
Fresh out East Atlanta with no manners damn
Fresh out East Atlanta
Bump on her bumper like a traffic jam jam
Hey I was quick to pay that girl like Uncle Sam here you go ayy
Back it on me shawty cravin' on me
Get to diggin' on me on me
She waited on me then what
Shawty cakin' on me got the bacon on me wait up
This is history in the makin' on me on me
Point blank close range that be
If it cost a million that's me that's me
I was gettin' mula man they feel me
Camila Cabello & Pharrell Williams:Havana ooh nana ayy ayy
Half of my heart is in Havana oohnana oh ayy ayy
He took me back to East Atlanta nanana oh no
All of my heart is in Havana ayy
My heart is in Havana ayy
Havana ooh nana
Starrah & Camila Cabello:Ooh nana oh nanana
Take me back back back like
Ooh nana oh nanana
Take me back back back like
Ooh nana oh nanana
Take me back back back like
Ooh nana oh nanana
Take me back back back
Yeah ayy
Ooohooohooh
Ooohooohooh
Take me back to my Havana
Camila Cabello & Pharrell Williams:Havana ooh nana ayy ayy
Half of my heart is in Havana oohnana oh yeah
He took me back to East Atlanta nanana
All of my heart is in Havana
My heart is in Havana ayy
Havana ooh nana
Camila Cabello & Starrah:Uh huh
Oh nanana
Oh nanana hey
Oh nanana
No no no take me back
Oh nanana
Havana ooh nana
'''
>>> song.count('back')
18

  

>>> test='''
人們都說:“桂林山水甲天下。”我們乘著木船,蕩漾在漓江上,來觀賞桂林的山水。我看見過波瀾壯闊的大海,玩賞過水平如鏡的西湖,卻從沒看見過漓江這樣的水。漓江的水真靜啊,靜得讓你感覺不到它在流動;漓江的水真清啊,清得可以看見江底的沙石;漓江的水真綠啊,綠得仿佛那是一塊無瑕的翡翠。船槳激起的微波擴散出一道道水紋,才讓你感覺到船在前進,岸在后移。我攀登過峰巒雄偉的泰山,游覽過紅葉似火的香山,卻從沒看見過桂林這一帶的山,桂林的山真奇啊,一座座拔地而起,各不相連,像老人,像巨象,像駱駝,奇峰羅列,形態萬千;桂林的山真秀啊,像翠綠的屏障,像新生的竹筍,色彩明麗,倒映水中;桂林的山真險啊,危峰兀立,怪石嶙峋,好像一不小心就會栽倒下來。這樣的山圍繞著這樣的水,這樣的水倒映著這樣的山,再加上空中云霧迷蒙,山間綠樹紅花,江上竹筏小舟,讓你感到像是走進了連綿不斷的畫卷,真是“舟行碧波上,人在畫中游”。'''
>>> test.replace(',',' ').replace('。',' ').replace('!',' ')
'\n人們都說:“桂林山水甲天下 ”我們乘著木船 蕩漾在漓江上 來觀賞桂林的山水 \n\u3000\u3000我看見過波瀾壯闊的大海 玩賞過水平如鏡的西湖 卻從沒看見過漓江這樣的水 漓江的水真靜啊 靜得讓你感覺不到它在流動;漓江的水真清啊 清得可以看見江底的沙石;漓江的水真綠啊 綠得仿佛那是一塊無瑕的翡翠 船槳激起的微波擴散出一道道水紋 才讓你感覺到船在前進 岸在后移 \n\u3000\u3000我攀登過峰巒雄偉的泰山 游覽過紅葉似火的香山 卻從沒看見過桂林這一帶的山 桂林的山真奇啊 一座座拔地而起 各不相連 像老人 像巨象 像駱駝 奇峰羅列 形態萬千;桂林的山真秀啊 像翠綠的屏障 像新生的竹筍 色彩明麗 倒映水中;桂林的山真險啊 危峰兀立 怪石嶙峋 好像一不小心就會栽倒下來 \n\u3000\u3000這樣的山圍繞著這樣的水 這樣的水倒映著這樣的山 再加上空中云霧迷蒙 山間綠樹紅花 江上竹筏小舟 讓你感到像是走進了連綿不斷的畫卷 真是“舟行碧波上 人在畫中游” '
>>> 

 

>>> test1 = test.split('str = ' '')
>>> print(test1)
['\n人們都說:“桂林山水甲天下。”我們乘著木船,蕩漾在漓江上,來觀賞桂林的山水。\n\u3000\u3000我看見過波瀾壯闊的大海,玩賞過水平如鏡的西湖,卻從沒看見過漓江這樣的水。漓江的水真靜啊,靜得讓你感覺不到它在流動;漓江的水真清啊,清得可以看見江底的沙石;漓江的水真綠啊,綠得仿佛那是一塊無瑕的翡翠。船槳激起的微波擴散出一道道水紋,才讓你感覺到船在前進,岸在后移。\n\u3000\u3000我攀登過峰巒雄偉的泰山,游覽過紅葉似火的香山,卻從沒看見過桂林這一帶的山,桂林的山真奇啊,一座座拔地而起,各不相連,像老人,像巨象,像駱駝,奇峰羅列,形態萬千;桂林的山真秀啊,像翠綠的屏障,像新生的竹筍,色彩明麗,倒映水中;桂林的山真險啊,危峰兀立,怪石嶙峋,好像一不小心就會栽倒下來。\n\u3000\u3000這樣的山圍繞著這樣的水,這樣的水倒映著這樣的山,再加上空中云霧迷蒙,山間綠樹紅花,江上竹筏小舟,讓你感到像是走進了連綿不斷的畫卷,真是“舟行碧波上,人在畫中游”。']

  

 

轉載于:https://www.cnblogs.com/oechen/p/8614168.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390017.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390017.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390017.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

POJ 3608 旋轉卡殼

思路&#xff1a; 旋轉卡殼應用 注意點&邊 邊&邊 點&點 三種情況 //By SiriusRen #include <cmath> #include <cstdio> #include <algorithm> using namespace std; const double eps1e-5; const int N10050; typedef double db; int n,m; str…

405. 數字轉換為十六進制數

405. 數字轉換為十六進制數 給定一個整數&#xff0c;編寫一個算法將這個數轉換為十六進制數。對于負整數&#xff0c;我們通常使用 補碼運算 方法。 注意: 十六進制中所有字母(a-f)都必須是小寫。 十六進制字符串中不能包含多余的前導零。如果要轉化的數為0&#xff0c;那么…

為什么我要重新開始數據科學

I’m feeling stuck.我感覺卡住了。 In my current work and in the content I create (videos and blog posts), I feel like I’ve begun to stall out. Most of the consumers of my content are at the start of their data science journey. The longer I’m in the fiel…

藍牙協議 HFP,HSP,A2DP,A2DP_CT,A2DP_TG,AVRCP,OPP,PBAP,SPP,FTP,TP,DTMF,DUN,SDP

簡介&#xff1a; HSP&#xff08;手機規格&#xff09;– 提供手機&#xff08;移動電話&#xff09;與耳機之間通信所需的基本功能。 HFP&#xff08;免提規格&#xff09;– 在 HSP 的基礎上增加了某些擴展功能&#xff0c;原來只用于從固定車載免提裝置來控制移動電話。 A2…

482. 密鑰格式化

482. 密鑰格式化 有一個密鑰字符串 S &#xff0c;只包含字母&#xff0c;數字以及 ‘-’&#xff08;破折號&#xff09;。其中&#xff0c; N 個 ‘-’ 將字符串分成了 N1 組。 給你一個數字 K&#xff0c;請你重新格式化字符串&#xff0c;使每個分組恰好包含 K 個字符。特…

安裝mariadb、安裝Apache

2019獨角獸企業重金招聘Python工程師標準>>> 安裝mariadb 安裝mariadb的步驟與安裝mysql的一樣 下載二進制源碼包 再用tar 解壓&#xff0c;創建/data/mariadb目錄和用戶 初始化 編譯啟動腳本 啟動 安裝Apache Apache是軟件基金會的名字&#xff0c;軟件的名字叫htt…

數據科學的發展_數據科學的發展與發展

數據科學的發展There’s perhaps nothing that sets the 21st century apart from others more than the concept of data. Every interaction we have with a connected device creates a data record, and beams it back to some data store for tracking and analysis. Inte…

Polling 、Long Polling 和 WebSocket

最近在學習研究WebSocket,了解到Polling 和Long Polling,翻閱了一些博文&#xff0c;根據自己的理解&#xff0c;做個學習筆記 Polling &#xff08;輪詢&#xff09;&#xff1a; 這種方式就是客戶端定時向服務器發送http的Get請求&#xff0c;服務器收到請求后&#xff0c;就…

慣性張量的推理_選擇合適的intel工作站處理器進行張量流推理和開發

慣性張量的推理With the increasing number of data scientists using TensorFlow, it might be a good time to discuss which workstation processor to choose from Intel’s lineup. You have several options to choose from:隨著使用TensorFlow的數據科學家數量的增加&am…

MongoDB數據庫查詢性能提高40倍

MongoDB數據庫查詢性能提高40倍 大家在使用 MongoDB 的時候有沒有碰到過性能問題呢&#xff1f;下面這篇文章主要給大家分享了MongoDB數據庫查詢性能提高40倍的經歷&#xff0c;需要的朋友可以參考借鑒&#xff0c;下面來一起看看吧。 前言 數據庫性能對軟件整體性能有著至關重…

通過Ajax方式上傳文件(input file),使用FormData進行Ajax請求

<script type"text/jscript">$(function () {$("#btn_uploadimg").click(function () {var fileObj document.getElementById("FileUpload").files[0]; // js 獲取文件對象if (typeof (fileObj) "undefined" || fileObj.size …

并發插入數據庫會導致失敗嗎_會導致業務失敗的數據分析方法

并發插入數據庫會導致失敗嗎The true value of data depends on business insight.Data analysis is one of the most powerful resources an enterprise has. However, if the tools and processes used are not friendly and widely available to the business users who nee…

434. 字符串中的單詞數

434. 字符串中的單詞數 統計字符串中的單詞個數&#xff0c;這里的單詞指的是連續的不是空格的字符。 請注意&#xff0c;你可以假定字符串里不包括任何不可打印的字符。 示例: 輸入: “Hello, my name is John” 輸出: 5 解釋: 這里的單詞是指連續的不是空格的字符&#x…

zooland 新開源的RPC項目,希望大家在開發的微服務的時候多一種選擇,讓微服務開發簡單,并且容易上手。...

zooland 我叫它動物園地&#xff0c;一個構思很長時間的一個項目。起初只是覺得各種通信框架都封裝的很好了&#xff0c;但是就是差些兼容&#xff0c;防錯&#xff0c;高可用。同時在使用上&#xff0c;不希望有多余的代碼&#xff0c;像普通接口一樣使用就可以了。 基于這些想…

187. 重復的DNA序列

187. 重復的DNA序列 所有 DNA 都由一系列縮寫為 ‘A’&#xff0c;‘C’&#xff0c;‘G’ 和 ‘T’ 的核苷酸組成&#xff0c;例如&#xff1a;“ACGAATTCCG”。在研究 DNA 時&#xff0c;識別 DNA 中的重復序列有時會對研究非常有幫助。 編寫一個函數來找出所有目標子串&am…

牛客網_Go語言相關練習_選擇題(2)

注&#xff1a;題目來源均出自牛客網。 一、選擇題 Map&#xff08;集合&#xff09;屬于Go的內置類型&#xff0c;不需要引入其它庫即可使用。 Go-Map_菜鳥教程 在函數聲明中&#xff0c;返回的參數要么都有變量名&#xff0c;要么都沒有。 C選項函數聲明語法有錯誤&#xff0…

機器學習模型部署_9月版部署機器學習模型

機器學習模型部署每月版 (MONTHLY EDITION) Often, the last step of a Data Science task is deployment. Let’s say you’re working at a big corporation. You’re building a project for a customer of the corporation and you’ve created a model that performs well…

352. 將數據流變為多個不相交區間

352. 將數據流變為多個不相交區間 給你一個由非負整數 a1, a2, …, an 組成的數據流輸入&#xff0c;請你將到目前為止看到的數字總結為不相交的區間列表。 實現 SummaryRanges 類&#xff1a; SummaryRanges() 使用一個空數據流初始化對象。void addNum(int val) 向數據流中…

Java常用的八種排序算法與代碼實現

排序問題一直是程序員工作與面試的重點&#xff0c;今天特意整理研究下與大家共勉&#xff01;這里列出8種常見的經典排序&#xff0c;基本涵蓋了所有的排序算法。 1.直接插入排序 我們經常會到這樣一類排序問題&#xff1a;把新的數據插入到已經排好的數據列中。將第一個數和第…

熊貓ai智能機器人量化_機器學習中的熊貓是什么

熊貓ai智能機器人量化Machine learning is a complex discipline. The implementation of machine learning models is now far much easier than it used to be, this is as a result of Machine learning frameworks such as pandas. Wait!! isnt panda an animal? As I rec…