當前位置:首頁 » 編程語言 » python抽獎程序

python抽獎程序

發布時間: 2022-10-02 11:45:38

『壹』 用python做一個程序:扔100次硬幣,然後分別顯示出擲出正面和反面的次數

7行代碼即可寫出程序,詳細步驟:

1、首先打開python自帶的IDLE,打開IDLE並ctrl+n新建如圖界面。

『貳』 python編寫抽獎程序

#data和name_data數據自己添加

import random



# 所有員工數據,字典的key是一個set類型,value是list類型

data = {

('能永年', '甲隊'): ['項目隊長', '曾經外派抵達x地做出了某事', '曾經外派抵達子公司做出了ss項目'],

('巴偉毅', '乙隊'): ['HR'],

('紀文博', '丙隊'): ['項目成員', '為xx事做出了重大貢獻', '曾經做過AA項目'],

('吉信鴻', '丙隊'): ['HR', '為公司面試了XX人次', ],

('沙雅旭', '丙隊'): ['財務管理', '針對財務的做出了重要指導'],

}name_data = ['能永年', '巴偉毅', '紀文博', '吉信鴻', '沙雅旭'] # 參見抽獎人的姓名random_name = random.choice(name_data) # 隨機一個中獎的人for key, value in data.items():# print(key,value)if random_name == key[0]: # 在字典key中找到這人print('{}:{}'.format(key[0], key[1]))for item in value: # 遍歷他的信息print(' ' + item.ljust(20))

『叄』 python的一個小程序怎麼寫

num1 = int(input())
num2 = int(input())
sum_all = 0
for i in range(num1,num2+1):
if i % 3 == 0 or i % 5 == 0:
sum_all += i
print(sum_all)

『肆』 公司年會要抽獎,那些抽獎的小程序是在那裡獲取的呀

年底已到,大大小小的公司都已經開始舉辦年會了,年會年年開,但是一般公司年會都是除了吃飯就是看節目,連最吸引人的抽獎環節也毫無新意。那麼,怎樣讓年會活動變得有新意呢?用箱子抽獎,全看台上的人表演了,太沒意思。那也可以來個好玩的,弄個轉盤進行抽獎活動。發一下自己寫的公司抽獎程序。需求:公司年會要一個抽獎程序,轉盤上的每一個人名是隨機中獎的,中獎後的人不可以再次中獎,按住抽獎,就會一直在轉,放開後,要再轉一兩圈才停。呵,剛好自己在學python cocos2d, 就用這個剛學的東東,雖然只學了點皮毛.首先我們看需求:我們想弄一個抽獎系統,在抽獎的時候我們希望針對不同的獎品有可以設置不同的中獎概率,還有就是我們不想一個時間馬上就把所有的獎品就發送出去了,最好能是在每幾名中產生一名。同時要兼顧後面的,不要前面的人把獎品全部抽走了後面就沒有獎品了。前端時間有個需求是客戶端雙端APP內嵌入整個轉盤抽獎的web子系統,具體是要在後台能夠控制大轉盤抽獎的獎項數,和用戶免費抽獎的次數,並且免費抽獎使用完,用戶可以觀看廣告進行抽獎或使用積分抽獎。正好最近有空,出了這篇教程,解析轉盤抽獎的實現過程。

『伍』 pycharm如何做抽獎

操作方法如下:
在pycharm中創建一個gift的項目
創建common包,在common包內分別創建error.py 、consts.py 、utils.py模塊。
創建storage包(其實就是個文件夾),創建user.json 、gift.json分別存儲用戶信息和獎品信息。
而我們的base、admin、user模塊則是直接創建在 gift的項目根目錄下即可。
PyCharm是一種Python IDE,帶有一整套可以幫助用戶在使用Python語言開發時提高其效率的工具,比如調試、語法高亮、Project管理、代碼跳轉、智能提示、自動完成、單元測試、版本控制。此外,該IDE提供了一些高級功能,以用於支持Django框架下的專業Web開發。

『陸』 我想用python寫一個生成隨機數的小程序.

import random
try:
while(True):
input= raw_input("Please enter 'Enter', 'q':<Quit>:")
if input == 'q':
break
print random.randint(1,100)
except Exception,data:
print "exit.%s"%data

『柒』 怎麼用python寫一個抽獎程序,是抽取圖片或視頻

16年年會抽獎網上有人對公司的抽獎結果又偏見,於是全員進行了抽獎代碼的review,好像是愛奇藝公司的,下面用python來實現一個抽獎程序。
主要功能有
1.從一個csv文件中讀入所有員工工號
2.將這些工號初始到一個列表中
3.用random模塊下的choice函數來隨機選擇列表中的一個工號
4.抽到的獎項的工號要從列表中進行刪除,以免再次抽到
初級版
這個比較簡單,缺少定製性,如沒法設置一等獎有幾名,二等獎有幾名
import csv#創建一個員工列表emplist = []#用with自動關閉文件with open('c://emps.csv') as f:
empf = csv.reader(f) for emp in empf:
emplist.append(emp)
print("進行一等獎抽獎,共有一名")import random#利用random模塊的chice函數來從列表中隨機選取一個元素e1 = random.choice(emplist)#將中獎的員工從列表中剔除emplist.remove(e1)
print('一等獎得主的號碼是 %s' % e1)
print('進行三個二等獎的號碼抽獎')
e2_1 = random.choice(emplist)
emplist.remove(e2_1)
e2_2 = random.choice(emplist)
emplist.remove(e2_2)
e2_3 = random.choice(emplist)
emplist.remove(e2_3)
print('獲得3個二等獎是 %s %s %s',(e2_1,e2_2,e2_3))#下面依次類推可以設置三等獎的抽獎

改進版
上面的那個初級版,假如要設置個三等獎一百名那麼將要重新維護幾百行代碼,下面用比較高級點的辦法實現.
我們考慮用面向對象來實現,設計一個抽獎類,類中包含一個屬性(號碼來源),一個方法:產生所有抽獎層次指定個數的抽獎號碼。
用到如下知識點:
1. csv模塊部分函數用法
2. sys模塊讀取輸入
3. random模塊函數choice函數用法
4. 列表和字典元素的添加、刪除
6. for循環中range用法
7. 類和面向對象
8. 字元列印,print中的計算
9.open中with
#!/usr/bin/python#coding=utf-8import csvimport sysimport random
reload(sys)
sys.setdefaultencoding('utf8')#coding=utf-8print("開始進行抽獎")#定義個抽獎類,功能有輸入抽獎級別和個數,列印出每個級別的抽獎員工號碼class Choujiang:
#定義scv文件路徑
def __init__(self,filepath):
self.empfile = filepath def creat_num(self):
emplist = [] with open(self.empfile) as f:
empf = csv.reader(f) for emp in empf:
emplist.append(emp)
print('共有%s 人參與抽獎' % len(emplist))
levels = int(input('抽獎分幾個層次,請輸入:')) #定義一個字典
level_dict = {} for i in range(0,levels):
print('請輸入當前獲獎層次 %s 對應的獎品個數' % ( i + 1))
str_level_dict_key = sys.stdin.readline()
int_level_dict_key = int(str_level_dict_key)
level_dict[i] = int_level_dict_key #循環完成後抽獎層次字典構造完畢
#進行抽獎開始
print('抽獎字典設置為: %s' % level_dict) for i in range(0,len(level_dict)):
winers = [] #產生當前抽獎層次i對應的抽獎個數
for j in range(0,int(level_dict[i])): #利用random模塊中的choice函數從列表中隨機產生一個
winer = random.choice(emplist)
winers.append(winer)
emplist.remove(winer)
print('抽獎層次 %s 下產出的獲獎人員有:' % (i + 1 ))
print(winers)#類功能定義完畢,開始初始化並使用if __name__ == '__main__':
peoples = Choujiang('c://emps.csv')
peoples.creat_num()

該段程序在python 2.6 以上及 3中均可以運行,運行結果如下圖:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "right", "credits" or "license()" for more information.>>> ================================ RESTART ================================>>> 開始進行抽獎
共有24790 人參與抽獎
抽獎分幾個層次,請輸入:2請輸入當前獲獎層次 1 對應的獎品個數1請輸入當前獲獎層次 2 對應的獎品個數3抽獎字典設置為: {0: 1, 1: 3}
抽獎層次 1 下產出的獲獎人員有:
[['張三19826']]
抽獎層次 2 下產出的獲獎人員有:
[['張三18670'], ['張三23235'], ['張三15705']]>>> 1234567891011121314151617

『捌』 怎麼樣用python做個程序!要從列表中抽取隨機取

import random
lis = ['%03d'%x for x in range(1,501)]
res = random.sample(lis,50)
for i,item in enumerate(res):
....print("%d :%s"%(i+1,item))

把. 換成縮進

『玖』 用python編程寫程序:兩個人分別投一個骰子,點數高的贏

摘要 python擲骰子

『拾』 python編程 編寫程序自動生成0到100間的一個隨機數,然後讓參與者輸入昵稱和數字,最後判斷誰猜得最准

#!/usr/bin/python3# -*- coding:utf-8 -*-"""@author:Storm_ck@file :20200605-01.py@time :2020/6/5 15:20""""""猜數字,看誰猜的最接近"""import randomdef get_abs(rannum, ansnum):return abs(ansnum - rannum)if __name__ == "__main__":num = random.randint(1, 100)adic = {}lens = 0while True:choice = input("What's your name?,enter to quit:")if choice == "enter":breakif choice != "enter":answer = int(input("What's your guess(1-100):"))lens += 1if choice in adic.keys():adic[choice] = answerelse:adic.setdefault(choice, answer)newlist = sorted(adic.items(), key = lambda kv: get_abs(num, kv[1]), reverse = False)if newlist[0][1] != newlist[1][1]:if num == newlist[0][1]:print("{} 厲害,數字就是{}:".format(newlist[0][0], newlist[0][1]))else:print("數字是{},猜的最接近的是:{}".format(num, newlist[0][0]))else:temp = []alist = list(zip(*newlist))[1]t = alist[0]for i in range(alist.count(t)):temp.append(newlist[i][0])astr = ",".join(temp)if num == t:print("{}都比較厲害,數字就是{}:".format(astr, num))else:print("數字是{},{}的答案相同,猜的最接近。".format(num, astr))

熱點內容
誤刪除文件夾恢復工具 發布:2024-04-24 20:31:57 瀏覽:383
php介面編寫 發布:2024-04-24 20:31:06 瀏覽:68
怎麼架設雙線伺服器 發布:2024-04-24 20:25:55 瀏覽:639
通易雲源碼 發布:2024-04-24 20:14:55 瀏覽:963
安卓手機卸載更新什麼意思 發布:2024-04-24 19:29:35 瀏覽:228
文件des加密 發布:2024-04-24 19:24:20 瀏覽:705
魔獸世界data文件夾 發布:2024-04-24 19:24:13 瀏覽:214
蘋果手機怎麼清空緩存 發布:2024-04-24 19:23:38 瀏覽:893
微信密碼沒有手機號如何找回 發布:2024-04-24 19:18:20 瀏覽:875
微雲解析源碼 發布:2024-04-24 19:13:58 瀏覽:792