大家好,小編來為大家解答以下問題,python可以做小程序研發(fā)嘛,python可以做小程序嗎,今天讓我們一起來看看吧!
Source code download: 本文相關(guān)源碼
人生苦短,快學Python!
在使用Python的過程中,我最喜歡的就是Python的各種第三方庫,能夠完成很多操作。
下面就給大家介紹5個通過Python構(gòu)建的項目,以此來學習Python編程python愛心代碼手機版。
一、石頭剪刀布游戲
目標:創(chuàng)建一個命令行游戲,游戲者可以在石頭、剪刀和布之間進行選擇,與計算機PK。如果游戲者贏了,得分就會添加,直到結(jié)束游戲時,最終的分數(shù)會展示給游戲者。
提示:接收游戲者的選擇,并且與計算機的選擇進行比較。計算機的選擇是從選擇列表中隨機選取的。如果游戲者獲勝,則增加1分。
import random
choices = [Rock, Paper, Scissors]
computer = random.choice(choices)
player = False
cpu_score = 0
player_score = 0
while True:
player = input(Rock, Paper or Scissors?).capitalize()
# 判斷游戲者和電腦的選擇
if player == computer:
print(Tie!)
elif player == Rock:
if computer == Paper:
print(You lose!, computer, covers, player)
cpu_score+=1
else:
print(You win!, player, smashes, computer)
player_score+=1
elif player == Paper:
if computer == Scissors:
print(You lose!, computer, cut, player)
cpu_score+=1
else:
print(You win!, player, covers, computer)
player_score+=1
elif player == Scissors:
if computer == Rock:
print(You lose..., computer, smashes, player)
cpu_score+=1
else:
print(You win!, player, cut, computer)
player_score+=1
elif player=='E':
print(Final Scores:)
print(fCPU:{cpu_score})
print(fPlaer:{player_score})
break
else:
print(That's not a valid play. Check your spelling!)
computer = random.choice(choices)
二、隨機密碼生成器
目標:創(chuàng)建一個程序,可指定密碼長度,生成一串隨機密碼。
提示:創(chuàng)建一個數(shù)字+大寫字母+小寫字母+特殊字符的字符串。根據(jù)設定的密碼長度隨機生成一串密碼。
import random
passlen = int(input(enter the length of password ))
s= abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKL MNOPQRSTUVIXYZ!aN$x*6*( )?
p = .join(random.sample(s,passlen ))
print(p)
----------------------------
enter the length of password
6
Za1gB0
三、骰子模擬器
目的:創(chuàng)建一個程序來模擬擲骰子。
提示:當用戶詢問時,使用random模塊生成一個1到6之間的數(shù)字。
import random;
while int(input('Press 1 to roll the dice or 0 to exit:\n')): print( random. randint(1,6))
--------------------------------------------------------------------
Press 1 to roll the dice or 0 to exit
1
4
四、自動發(fā)送郵件
目的:編寫一個Python腳本,可以使用這個腳本發(fā)送電子郵件。
提示:email庫可用于發(fā)送電子郵件。
import smtplib
from email.message import EmailMessage
email = EmailMessage() ## Creating a object for EmailMessage
email['from'] = 'xyz name' ## Person who is sending
email['to'] = 'xyz id' ## Whom we are sending
email['subject'] = 'xyz subject' ## Subject of email
email.set_content(Xyz content of email) ## content of email
with smtlib.SMTP(host='smtp.gmail.com',port=587)as smtp:
## sending request to server
smtp.ehlo() ## server object
smtp.starttls() ## used to send data between server and client
smtp.login(email_id,Password) ## login id and password of gmail
smtp.send_message(email) ## Sending email
print(email send) ## Printing success message
五、鬧鐘
目的:編寫一個創(chuàng)建鬧鐘的Python腳本。
提示:你可以使用date-time模塊創(chuàng)建鬧鐘,以及playsound庫播放聲音。
from datetime import datetime
from playsound import playsound
alarm_time = input(Enter the time of alarm to be set:HH:MM:SS\n)
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print(Setting up alarm..)
while True:
now = datetime.now()
current_hour = now.strftime(%I)
current_minute = now.strftime(%M)
current_seconds = now.strftime(%S)
current_period = now.strftime(%p)
if(alarm_period==current_period):
if(alarm_hour==current_hour):
if(alarm_minute==current_minute):
if(alarm_seconds==current_seconds):
print(Wake Up!)
playsound('audio.mp3') ## download the alarm sound from link
break
關(guān)于Python技術(shù)儲備
學好 Python 不論是就業(yè)還是做副業(yè)賺錢都不錯,但要學會 Python 還是要有一個學習規(guī)劃。最后大家分享一份全套的 Python 學習資料,給那些想學習 Python 的小伙伴們一點幫助!
一、Python所有方向的學習路線
Python所有方向路線就是把Python常用的技術(shù)點做整理,形成各個領(lǐng)域的知識點匯總,它的用處就在于,你可以按照上面的知識點去找對應的學習資源,保證自己學得較為全面。
二、學習軟件
工欲善其事必先利其器。學習Python常用的開發(fā)軟件都在這里了,給大家節(jié)省了很多時間。
三、入門學習視頻
我們在看視頻學習的時候,不能光動眼動腦不動手,比較科學的學習方法是在理解之后運用它們,這時候練手項目就很適合了。
四、實戰(zhàn)案例
光學理論是沒用的,要學會跟著一起敲,要動手實操,才能將自己的所學運用到實際當中去,這時候可以搞點實戰(zhàn)案例來學習。
五、面試資料
我們學習Python必然是為了找到高薪的工作,下面這些面試題是來自阿里、騰訊、字節(jié)等一線互聯(lián)網(wǎng)大廠最新的面試資料,并且有阿里大佬給出了權(quán)威的解答,刷完這一套面試資料相信大家都能找到滿意的工作。
這份完整版的Python全套學習資料已經(jīng)上傳CSDN,朋友們?nèi)绻枰梢晕⑿艗呙柘路紺SDN官方認證二維碼免費領(lǐng)取【保證100%免費
】
文章來源:http://www.zghlxwxcb.cn/news/detail-811157.html
Python資料、技術(shù)、課程、解答、咨詢也可以直接點擊下面名片,
添加官方客服斯琪
↓
文章來源地址http://www.zghlxwxcb.cn/news/detail-811157.html
人生苦短,快學Python!
在使用Python的過程中,我最喜歡的就是Python的各種第三方庫,能夠完成很多操作。
下面就給大家介紹5個通過Python構(gòu)建的項目,以此來學習Python編程python愛心代碼手機版。
一、石頭剪刀布游戲
目標:創(chuàng)建一個命令行游戲,游戲者可以在石頭、剪刀和布之間進行選擇,與計算機PK。如果游戲者贏了,得分就會添加,直到結(jié)束游戲時,最終的分數(shù)會展示給游戲者。
提示:接收游戲者的選擇,并且與計算機的選擇進行比較。計算機的選擇是從選擇列表中隨機選取的。如果游戲者獲勝,則增加1分。
import random
choices = [Rock, Paper, Scissors]
computer = random.choice(choices)
player = False
cpu_score = 0
player_score = 0
while True:
player = input(Rock, Paper or Scissors?).capitalize()
# 判斷游戲者和電腦的選擇
if player == computer:
print(Tie!)
elif player == Rock:
if computer == Paper:
print(You lose!, computer, covers, player)
cpu_score+=1
else:
print(You win!, player, smashes, computer)
player_score+=1
elif player == Paper:
if computer == Scissors:
print(You lose!, computer, cut, player)
cpu_score+=1
else:
print(You win!, player, covers, computer)
player_score+=1
elif player == Scissors:
if computer == Rock:
print(You lose..., computer, smashes, player)
cpu_score+=1
else:
print(You win!, player, cut, computer)
player_score+=1
elif player=='E':
print(Final Scores:)
print(fCPU:{cpu_score})
print(fPlaer:{player_score})
break
else:
print(That's not a valid play. Check your spelling!)
computer = random.choice(choices)
二、隨機密碼生成器
目標:創(chuàng)建一個程序,可指定密碼長度,生成一串隨機密碼。
提示:創(chuàng)建一個數(shù)字+大寫字母+小寫字母+特殊字符的字符串。根據(jù)設定的密碼長度隨機生成一串密碼。
import random
passlen = int(input(enter the length of password ))
s= abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKL MNOPQRSTUVIXYZ!aN$x*6*( )?
p = .join(random.sample(s,passlen ))
print(p)
----------------------------
enter the length of password
6
Za1gB0
三、骰子模擬器
目的:創(chuàng)建一個程序來模擬擲骰子。
提示:當用戶詢問時,使用random模塊生成一個1到6之間的數(shù)字。
import random;
while int(input('Press 1 to roll the dice or 0 to exit:\n')): print( random. randint(1,6))
--------------------------------------------------------------------
Press 1 to roll the dice or 0 to exit
1
4
四、自動發(fā)送郵件
目的:編寫一個Python腳本,可以使用這個腳本發(fā)送電子郵件。
提示:email庫可用于發(fā)送電子郵件。
import smtplib
from email.message import EmailMessage
email = EmailMessage() ## Creating a object for EmailMessage
email['from'] = 'xyz name' ## Person who is sending
email['to'] = 'xyz id' ## Whom we are sending
email['subject'] = 'xyz subject' ## Subject of email
email.set_content(Xyz content of email) ## content of email
with smtlib.SMTP(host='smtp.gmail.com',port=587)as smtp:
## sending request to server
smtp.ehlo() ## server object
smtp.starttls() ## used to send data between server and client
smtp.login(email_id,Password) ## login id and password of gmail
smtp.send_message(email) ## Sending email
print(email send) ## Printing success message
五、鬧鐘
目的:編寫一個創(chuàng)建鬧鐘的Python腳本。
提示:你可以使用date-time模塊創(chuàng)建鬧鐘,以及playsound庫播放聲音。
from datetime import datetime
from playsound import playsound
alarm_time = input(Enter the time of alarm to be set:HH:MM:SS\n)
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()
print(Setting up alarm..)
while True:
now = datetime.now()
current_hour = now.strftime(%I)
current_minute = now.strftime(%M)
current_seconds = now.strftime(%S)
current_period = now.strftime(%p)
if(alarm_period==current_period):
if(alarm_hour==current_hour):
if(alarm_minute==current_minute):
if(alarm_seconds==current_seconds):
print(Wake Up!)
playsound('audio.mp3') ## download the alarm sound from link
break
關(guān)于Python技術(shù)儲備
學好 Python 不論是就業(yè)還是做副業(yè)賺錢都不錯,但要學會 Python 還是要有一個學習規(guī)劃。最后大家分享一份全套的 Python 學習資料,給那些想學習 Python 的小伙伴們一點幫助!
一、Python所有方向的學習路線
Python所有方向路線就是把Python常用的技術(shù)點做整理,形成各個領(lǐng)域的知識點匯總,它的用處就在于,你可以按照上面的知識點去找對應的學習資源,保證自己學得較為全面。
二、學習軟件
工欲善其事必先利其器。學習Python常用的開發(fā)軟件都在這里了,給大家節(jié)省了很多時間。
三、入門學習視頻
我們在看視頻學習的時候,不能光動眼動腦不動手,比較科學的學習方法是在理解之后運用它們,這時候練手項目就很適合了。
四、實戰(zhàn)案例
光學理論是沒用的,要學會跟著一起敲,要動手實操,才能將自己的所學運用到實際當中去,這時候可以搞點實戰(zhàn)案例來學習。
五、面試資料
我們學習Python必然是為了找到高薪的工作,下面這些面試題是來自阿里、騰訊、字節(jié)等一線互聯(lián)網(wǎng)大廠最新的面試資料,并且有阿里大佬給出了權(quán)威的解答,刷完這一套面試資料相信大家都能找到滿意的工作。
這份完整版的Python全套學習資料已經(jīng)上傳CSDN,朋友們?nèi)绻枰梢晕⑿艗呙柘路紺SDN官方認證二維碼免費領(lǐng)取【保證100%免費
】
Python資料、技術(shù)、課程、解答、咨詢也可以直接點擊下面名片,
添加官方客服斯琪
↓
到了這里,關(guān)于python可以做小程序研發(fā)嘛,python可以做小程序嗎的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!