最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

五個(gè)Python迷你版小程序附代碼

 更新時(shí)間:2021年11月18日 10:36:13   作者:Python學(xué)習(xí)與數(shù)據(jù)挖掘  
在使用Python的過(guò)程中,我最喜歡的就是Python的各種第三方庫(kù),能夠完成很多操作。下面就給大家介紹5個(gè)通過(guò) Python 構(gòu)建的實(shí)戰(zhàn)項(xiàng)目,來(lái)實(shí)踐 Python 編程能力。歡迎收藏學(xué)習(xí),喜歡點(diǎn)贊支持

一、石頭剪刀布游戲

目標(biāo):創(chuàng)建一個(gè)命令行游戲,游戲者可以在石頭、剪刀和布之間進(jìn)行選擇,與計(jì)算機(jī)PK。如果游戲者贏了,得分就會(huì)添加,直到結(jié)束游戲時(shí),最終的分?jǐn)?shù)會(huì)展示給游戲者。

提示:接收游戲者的選擇,并且與計(jì)算機(jī)的選擇進(jìn)行比較。計(jì)算機(jī)的選擇是從選擇列表中隨機(jī)選取的。如果游戲者獲勝,則增加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(f"CPU:{cpu_score}")
        print(f"Plaer:{player_score}")
        break
    else:
        print("That's not a valid play. Check your spelling!")
    computer = random.choice(choices)

二、隨機(jī)密碼生成器

目標(biāo):創(chuàng)建一個(gè)程序,可指定密碼長(zhǎng)度,生成一串隨機(jī)密碼。

提示:創(chuàng)建一個(gè)數(shù)字+大寫字母+小寫字母+特殊字符的字符串。根據(jù)設(shè)定的密碼長(zhǎng)度隨機(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)建一個(gè)程序來(lái)模擬擲骰子。

提示:當(dāng)用戶詢問(wèn)時(shí),使用random模塊生成一個(gè)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

四、自動(dòng)發(fā)送郵件

目的:編寫一個(gè)Python腳本,可以使用這個(gè)腳本發(fā)送電子郵件。

提示:email庫(kù)可用于發(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

五、鬧鐘

目的:編寫一個(gè)創(chuàng)建鬧鐘的Python腳本。

提示:你可以使用date-time模塊創(chuàng)建鬧鐘,以及playsound庫(kù)播放聲音。

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

技術(shù)交流

歡迎轉(zhuǎn)載、收藏、有所收獲點(diǎn)贊支持一下!

在這里插入圖片描述

到此這篇關(guān)于五個(gè)Python迷你版小游戲附代碼的文章就介紹到這了,更多相關(guān)Python 游戲內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 對(duì)pandas的層次索引與取值的新方法詳解

    對(duì)pandas的層次索引與取值的新方法詳解

    今天小編就為大家分享一篇對(duì)pandas的層次索引與取值的新方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Python 使用input同時(shí)輸入多個(gè)數(shù)的操作

    Python 使用input同時(shí)輸入多個(gè)數(shù)的操作

    這篇文章主要介紹了Python 使用input同時(shí)輸入多個(gè)數(shù)的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-03-03
  • Python模塊包中__init__.py文件功能分析

    Python模塊包中__init__.py文件功能分析

    這篇文章主要介紹了Python模塊包中__init__.py文件功能,簡(jiǎn)單分析了__init__.py在調(diào)入模塊和包的過(guò)程中的作用,需要的朋友可以參考下
    2016-06-06
  • python實(shí)現(xiàn)數(shù)據(jù)預(yù)處理之填充缺失值的示例

    python實(shí)現(xiàn)數(shù)據(jù)預(yù)處理之填充缺失值的示例

    下面小編就為大家分享一篇python實(shí)現(xiàn)數(shù)據(jù)預(yù)處理之填充缺失值的示例。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • Python繪制散點(diǎn)密度圖的三種方式詳解

    Python繪制散點(diǎn)密度圖的三種方式詳解

    散點(diǎn)密度圖是在散點(diǎn)圖的基礎(chǔ)上,計(jì)算了每個(gè)散點(diǎn)周圍分布了多少其他的點(diǎn),并通過(guò)顏色表現(xiàn)出來(lái)。本文主要介紹了Python繪制散點(diǎn)密度圖的三種方式,需要的可以參考下
    2022-06-06
  • 淺析Python?WSGI的使用

    淺析Python?WSGI的使用

    WSGI也稱之為web服務(wù)器通用網(wǎng)關(guān)接口,全稱是web?server?gateway?interface。這篇文章主要為大家介紹了Python?WSGI的使用,希望對(duì)大家有所幫助
    2023-04-04
  • python爬蟲爬取某網(wǎng)站視頻的示例代碼

    python爬蟲爬取某網(wǎng)站視頻的示例代碼

    這篇文章主要介紹了python爬蟲爬取某網(wǎng)站視頻的示例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-02-02
  • Django?ORM?多表查詢示例代碼

    Django?ORM?多表查詢示例代碼

    這篇文章主要介紹了Django?ORM?多表查詢,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-09-09
  • Python 多張圖片合并成一個(gè)pdf的參考示例

    Python 多張圖片合并成一個(gè)pdf的參考示例

    最近需要將記的筆記整理成一個(gè)pdf進(jìn)行保存,所以就研究了一下如何利用 Python 代碼將拍下來(lái)的照片整個(gè)合并成一個(gè)pdf
    2021-06-06
  • python實(shí)現(xiàn)批量壓縮指定目錄下的文件夾

    python實(shí)現(xiàn)批量壓縮指定目錄下的文件夾

    這篇文章主要介紹了利用Python實(shí)現(xiàn)批量壓縮指定目錄下的文件夾的示例代碼,文中代碼示例講解詳細(xì),感興趣的小伙伴快跟隨小編一起動(dòng)手試一試
    2023-08-08

最新評(píng)論

涪陵区| 双辽市| 陆丰市| 油尖旺区| 枝江市| 南木林县| 长垣县| 黄石市| 和田县| 井陉县| 麻阳| 正蓝旗| 城市| 佳木斯市| 隆回县| 金门县| 中阳县| 凤翔县| 武冈市| 高青县| 泰兴市| 玉田县| 象州县| 松江区| 尼木县| 海门市| 晋州市| 日照市| 友谊县| 会理县| 四平市| 阆中市| 通化县| 怀化市| 房产| 汶上县| 华阴市| 双辽市| 惠东县| 岚皋县| 汾西县|