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

3個(gè)適合新手練習(xí)的python小游戲

 更新時(shí)間:2022年01月12日 08:55:55   作者:愛摸魚的菜鳥碼農(nóng)  
這篇文章主要分析的是3個(gè)適合新手練習(xí)的python小游戲,初學(xué)者嘛就應(yīng)該多練手,下文分享的python小游戲歡迎大家來玩,需要的小伙伴也可以參考一下

學(xué)Python之前我們先來幾個(gè)簡單的小游戲練練手,這三個(gè)小游戲一個(gè)比一個(gè)復(fù)雜,建議新手慢慢來:

1.猜拳

import random ?#導(dǎo)入隨機(jī)模塊
?
num = 1
yin_num = 0
shu_num = 0
while num <= 3:
? ? if shu_num == 2 or yin_num == 2:
? ? ? ? break
? ? user = int(input('請(qǐng)出拳 0(石頭) 1(剪刀) 2(布)'))
? ? if user > 2:
? ? ? ? print('不能出大于2的值')
? ? else:
? ? ? ? data = ['石頭', '剪刀', '布']
? ? ? ? com = random.randint(0, 2)
? ? ? ? print("您出的是{},電腦出的是{}".format(data[user], data[com]))
? ? ? ? if user == com:
? ? ? ? ? ? print('平局')
? ? ? ? ? ? continue
? ? ? ? elif (user == 0 and com == 1) or (user == 1 and com == 2) or (user == 2 and com == 0):
? ? ? ? ? ? print('你贏了')
? ? ? ? ? ? yin_num += 1
? ? ? ? else:
? ? ? ? ? ? print('你輸了')
? ? ? ? ? ? shu_num += 1
? ? num += 1

2.數(shù)字炸彈

import random
import time
?
bomb = random.randint(1, 99)
print(bomb)
start = 0
end = 99
while 1 == 1:
?
? ? people = int(input('請(qǐng)輸入{}到{}之間的數(shù):'.format(start, end)))
? ? if people > bomb:
? ? ? ? print('大了')
? ? ? ? end = people
? ? elif people < bomb:
? ? ? ? print('小了')
? ? ? ? start = people
? ? else:
? ? ? ? print('BOOM!!!')
? ? ? ? break
? ? print('等待電腦了輸入{}到{}之間的數(shù):'.format(start, end))
? ? time.sleep(1)
? ? com = random.randint(start + 1, end - 1)
? ? print('電腦輸入:{}'.format(com))
? ? if com > bomb:
? ? ? ? print('大了')
? ? ? ? end = com
? ? elif com < bomb:
? ? ? ? print('小了')
? ? ? ? start = com
? ? else:
? ? ? ? print('BOOM!!!')
? ? ? ? break

3.賭大小

import time
import random
# 讓用戶注冊(cè)
name = input('請(qǐng)?zhí)顚懹脩裘?)
age = input("{}您好,請(qǐng)輸入您的年齡 : ".format(name))
user_info = {'name': name, 'age': int(age)} ?# 用戶信息
user_properties = ['X 1-5'] ?# 用于存放用戶道具 默認(rèn)道具
properties = ['X3 (250G)', 'X1-5 (300G)'] ?# 道具列表 顯示用
?
# 根據(jù)用戶年齡 給與不同的初始金幣
if 10 < user_info['age'] < 18:
? ? glod = 1000
elif 18 <= user_info['age'] <= 30:
? ? glod = 1500
else:
? ? glod = 500
user_info['glod'] = glod
?
# 輸出相關(guān)提示信息
print("{}您好,歡迎游玩本游戲,您的初始金幣為:{}".format(user_info['name'], user_info['glod']))
print("\n")
time.sleep(1)
print('游戲說明'.center(50, '*'))
print('*'.ljust(53), '*')
print('*', end='')
print("電腦每次投擲三枚骰子,總點(diǎn)數(shù)>=10為大,否則為小".center(32), end='')
print('*')
print('*'.ljust(53), '*')
print('*' * 54)
print("\n")
?
# ? ? ? ? ? ? 開始游戲
result = input('是否開始游戲 yes or no : ?')
go = True
if (result.lower() == 'yes'):
? ? while go:
? ? ? ? dices = []
? ? ? ? # 開始投擲
? ? ? ? for i in range(0, 3):
? ? ? ? ? ? dices.append(random.randint(1, 6))
? ? ? ? total = sum(dices) ?# 計(jì)算總和
? ? ? ? user_input = input('請(qǐng)輸入big OR small : ') ?# 等待用戶輸入
? ? ? ? u_input = user_input.strip().lower()
? ? ? ? time.sleep(1)
? ? ? ? # 判斷用戶輸入
? ? ? ? print('骰子點(diǎn)數(shù)為:{}'.format(dices), end=' ')
? ? ? ? if (total >= 10 and u_input == 'big') or (total < 10 and u_input == 'small'):
? ? ? ? ? ? print('您贏了!!!')
? ? ? ? ? ? multi = 1 ?# 倍數(shù)
? ? ? ? ? ? if len(user_properties) > 0: ?# 如果用戶有道具 選擇是否使用道具
? ? ? ? ? ? ? ? use_pro = input('是否使用道具: ')
? ? ? ? ? ? ? ? if use_pro.lower() == 'yes':
? ? ? ? ? ? ? ? ? ? use_pro = int(input('請(qǐng)選擇使用第幾個(gè)道具{} :'.format(user_properties)))
? ? ? ? ? ? ? ? ? ? use_pro -= 1
? ? ? ? ? ? ? ? ? ? # 判斷道具類型
? ? ? ? ? ? ? ? ? ? if user_properties[use_pro] == 'X 3':
? ? ? ? ? ? ? ? ? ? ? ? multi = 3
? ? ? ? ? ? ? ? ? ? ? ? print('獎(jiǎng)金翻3倍')
? ? ? ? ? ? ? ? ? ? elif user_properties[use_pro] == 'X 1-5':
? ? ? ? ? ? ? ? ? ? ? ? multi = random.randint(1, 5)
? ? ? ? ? ? ? ? ? ? ? ? print('獎(jiǎng)金翻{}倍'.format(multi))
? ? ? ? ? ? ? ? ? ? user_properties.remove(user_properties[use_pro]) ?# 刪除道具
?
? ? ? ? ? ? user_info['glod'] += 100 * multi; ?# 金額增加
? ? ? ? else:
? ? ? ? ? ? print('您輸了!')
? ? ? ? ? ? user_info['glod'] -= 100; ?# 錯(cuò)誤 用戶金幣減 100
?
? ? ? ? # 判斷用戶金幣 是否夠下次玩 不夠則退出程序
? ? ? ? if (user_info['glod'] <= 0):
? ? ? ? ? ? print('您的金幣已經(jīng)用完,感謝您的游玩')
? ? ? ? ? ? break
?
? ? ? ? if user_info['glod'] % 1000 == 0: ?# 用戶金幣 是1000的倍數(shù)是 可購買道具
? ? ? ? ? ? shop = input('您現(xiàn)在有金幣:{},是否購買道具 yes or no: '.format(user_info['glod']))
? ? ? ? ? ? if shop.lower() == 'yes':
? ? ? ? ? ? ? ? good_num = int(input('請(qǐng)選擇要購買第幾個(gè)道具 {}'.format(properties)))
? ? ? ? ? ? ? ? if good_num == 1:
? ? ? ? ? ? ? ? ? ? user_properties.append('X 3') ?# 給用戶添加道具
? ? ? ? ? ? ? ? ? ? user_info['glod'] -= 250
? ? ? ? ? ? ? ? ? ? print('購買成功!消耗金幣250')
? ? ? ? ? ? ? ? elif good_num == 2:
? ? ? ? ? ? ? ? ? ? user_properties.append('X 1-5') ?# 給用戶添加道具
? ? ? ? ? ? ? ? ? ? user_info['glod'] -= 300 ?# 用戶金幣減 300
? ? ? ? ? ? ? ? ? ? print('購買成功!消耗金幣300')
? ? ? ? ? ? ? ? else:
? ? ? ? ? ? ? ? ? ? print('沒有該道具,您失去了這次機(jī)會(huì)')
? ? ? ? else:
? ? ? ? ? ? # ?一直提示 太煩
? ? ? ? ? ? # conti = input('您現(xiàn)在有金幣:{},是否繼續(xù)游玩,yes or no: '.format(user_info['glod']))
? ? ? ? ? ? print('您現(xiàn)在有金幣:{} '.format(user_info['glod']))
else:
? ? print('歡迎下次游玩,再見!')

到此這篇關(guān)于3個(gè)適合新手練習(xí)的python小游戲的文章就介紹到這了,更多相關(guān)python小游戲練習(xí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python 列表的基本操作介紹

    Python 列表的基本操作介紹

    這篇文章主要介紹了Python 列表的基本操作,下面文章圍繞Python 列表的相關(guān)資料展開文章的詳細(xì)內(nèi)容,,需要的朋友可以參考一下,希望對(duì)大家有所幫助
    2021-11-11
  • Django自定義User模型、認(rèn)證、權(quán)限控制的操作

    Django自定義User模型、認(rèn)證、權(quán)限控制的操作

    這篇文章主要介紹了Django自定義User模型、認(rèn)證、權(quán)限控制的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • Django中ORM的基本使用教程

    Django中ORM的基本使用教程

    這篇文章主要給大家介紹了關(guān)于Django中ORM基本使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Python中常見的矩陣運(yùn)算詳解

    Python中常見的矩陣運(yùn)算詳解

    這篇文章主要介紹了Python中常見的矩陣運(yùn)算詳解,所謂的數(shù)據(jù)處理,其本質(zhì)大都可以歸為矩陣運(yùn)算,因?yàn)樾枰幚淼臄?shù)據(jù)大都是矩陣或向量的形式,一個(gè)工具適不適合做數(shù)據(jù)處理,一個(gè)重要的指標(biāo)的就是支不支持矩陣運(yùn)算,需要的朋友可以參考下
    2023-08-08
  • 在PyTorch中實(shí)現(xiàn)可解釋的神經(jīng)網(wǎng)絡(luò)模型的方法詳解

    在PyTorch中實(shí)現(xiàn)可解釋的神經(jīng)網(wǎng)絡(luò)模型的方法詳解

    這篇文章主要為大家介紹在PyTorch如何中實(shí)現(xiàn)可解釋的神經(jīng)網(wǎng)絡(luò)模型,并為您提供使用簡單的 PyTorch 接口實(shí)現(xiàn)最先進(jìn)的基于概念的模型的工具,需要的朋友可以參考下
    2023-06-06
  • Python開多次方根的案例

    Python開多次方根的案例

    這篇文章主要介紹了Python開多次方根的案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Python中對(duì)象的引用與復(fù)制的使用

    Python中對(duì)象的引用與復(fù)制的使用

    引用和復(fù)制是Python處理對(duì)象的重要概念,本文主要介紹了Python中對(duì)象的引用與復(fù)制的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-12-12
  • python3連接mysql獲取ansible動(dòng)態(tài)inventory腳本

    python3連接mysql獲取ansible動(dòng)態(tài)inventory腳本

    Ansible Inventory 是包含靜態(tài) Inventory 和動(dòng)態(tài) Inventory 兩部分的,靜態(tài) Inventory 指的是在文件中指定的主機(jī)和組,動(dòng)態(tài) Inventory 指通過外部腳本獲取主機(jī)列表。這篇文章主要介紹了python3連接mysql獲取ansible動(dòng)態(tài)inventory腳本,需要的朋友可以參考下
    2020-01-01
  • python目標(biāo)檢測(cè)IOU的概念與示例

    python目標(biāo)檢測(cè)IOU的概念與示例

    這篇文章主要為大家介紹了python目標(biāo)檢測(cè)IOU的概念與示例實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • 利用python中pymysql操作MySQL數(shù)據(jù)庫的新手指南

    利用python中pymysql操作MySQL數(shù)據(jù)庫的新手指南

    PyMySQL是在Python3.x版本中用于連接MySQL服務(wù)器的一個(gè)庫,Python2中是使用mysqldb,這篇文章主要給大家介紹了關(guān)于利用python中pymysql操作MySQL數(shù)據(jù)庫的相關(guān)資料,需要的朋友可以參考下
    2021-09-09

最新評(píng)論

淮阳县| 东丰县| 射洪县| 七台河市| 天峨县| 福贡县| 巫溪县| 瓦房店市| 萍乡市| 新乡县| 永康市| 香河县| 昌平区| 汶上县| 静海县| 淳化县| 赤峰市| 肃宁县| 义马市| 山东| 云浮市| 德化县| 宽城| 中山市| 彰武县| 化州市| 通化市| 大竹县| 行唐县| 河南省| 英超| 松原市| 黄梅县| 梧州市| 乌鲁木齐市| 双辽市| 会昌县| 九龙城区| 乌拉特后旗| 阳西县| 紫金县|