A. 如何用python寫一個從題庫自動匹配的答題腳本
#!/usr/bin/envpythonimportsysstr=Truewhile(str):dig=int(input())ifdig>100:print'pleaseinputmunbetween0~100'elifdig>=90:print'A'elifdig>=80:print'B'elifdig>=70:print'C'elifdig>=60:prin
B. python編程問題
可以使用 Python 的 itertools 模塊來生成所有可能的組合,然後再計算每個組森蘆合的和。以下是示例代碼:

在此代碼中,我們首先使用 itertools.combinations() 函數生成了所有可能的組合,並將它們存儲在一個名為 combinations 的列表中。然後,我此掘帶們對列表中的每個組合求和,將它們存儲在另一個名為 sums 的列表中。最後,我們通過將 sums 轉換為一個集合來確定唯一的和,並列印出我們找到的所有唯一和的數量以及它們各自的值。
請注意,如果數字非散歲常多或者復雜度高,則可能需要考慮優化該代碼,以便更有效地生成和計算組合的和。
C. 怎麼用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
D. Python操作實驗題,需要詳細源代碼,求求各位計算機大神
按照題目要求編寫的Python程序如下
(注意 幸運數應該是前兩位數字之和等於後兩位數字之和的四位正整數)
第1題
def luck_number(n):
if len(str(n))==4:
a=n%10;
b=n//10%10
c=n//100%10
d=n//1000%10
if d+c==b+a:
return True
else:
return False
else:
return False
a,b=input().split()
count=0
for i in range(int(a),int(b)+1):
if luck_number(i)==True:
count+=1
if count%5==0:
print("%d"% i)
else:
print("%d "% i,end='')
源代碼(注意源代碼的縮進)

E. Python代碼問題,求助!
拼接到data字典中的text的content中就可以了;
import requests,random
from datetime import datetime
url = '' #新棟機器人的webhook地址
headers = {'Content-type':'application/json'}
content_text = "各位同事,早上好!記得填寫上午匯報哦~,今天抽查的宿舍是:"+random.sample([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],5)
data = {
"msgtype": "text",
"text": {
"content": content_text , #要發送的文字
"mentioned_list": ["@all"], #要@的人,可以是特定的人
}
}
r = requests.post(url,headers=headers,json=data)
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"文本發送情況提示",r.text)