導航:首頁 > 編程語言 > 新浪level2python

新浪level2python

發布時間:2022-11-26 10:47:17

㈠ 新浪level2 web版還能使用嗎

不可以
因為新浪level2的數據介面已經下架。
Level-2產品是由上海證券交易所推出的實時行情信息收費服務,主要提供在上海證券交易所上市交易的證券產品的實時交易數據。包括十檔行情,買賣隊列,逐筆成交,委託總量和加權價格等多種新式數據。使用Level-2軟體的股民,在開盤時間內,可以隨時看到莊家、散戶買賣股票的情況。

python習題,求救!!!

1:

使用高階函數filter

新列表=list(filter(lambdax:x%2==0,原列表))

2:

使用while循環輸入,保存到列表,然後使用sum(列表)/len(列表)得到平均分

L=[]
whileTrue:
s=input('請輸入成績:')
ifs.isdigit():
L.append(int(s))
s=input('是否繼續輸入?')
ifs!='yes':
break
else:
break
print('輸入的成績:',L)
iflen(L)>0:
print('平均成績:',sum(L)/len(L))

3.

使用re來判斷

importre


classPasswordHelper(object):
rules=['[A-Z]+',
'[a-z]+',
r'd+',
'[\'+'\'.join('+-*/')+']',#特殊符號+-*/
]
deflevel(self,password):
iflen(password)>=6:
returnsum(list(1ifre.search(r,password)else0
forrinself.rules))
return0


pwd=PasswordHelper()
print(pwd.level('asdf'))
print(pwd.level('testpasswordhelper'))
print(pwd.level('TestPasswordHelper'))
print(pwd.level('TestPasswordHelper1'))
print(pwd.level('TestPasswordHelper-1'))

㈢ 求Python大佬幫解

第(1)問中添加的新同學小何,其學號與小吳重復了,感覺應該改為20210338

python代碼和運行結果如下:

輸出實現了添加新記錄,列印出了每位同學的信息,並判斷了每個人成績的等級

源碼

# -*- coding: utf-8 -*-

def level(score):

if score>=80 and score<=100:

return 'A'

elif score>=60 and score<80:

return 'B'

elif score>=0 and score<60:

return 'C'

list1=[['小張',20210334,89], ['小李',20210335,58],

['小王',20210336,94], ['小吳',20210337,85]]

list1.append(['小何',20210338,77])

for l in list1:

print('學號為%d的同學%s,本次測試的成績為%d分' % (l[1], l[0], l[2]))

print('成績等級為', level(l[2]), sep='')

㈣ 誰能幫我解釋下一下python命令的意思啊

是一種面向對象、直譯式計算機程序設計語言,也是一種功能強大的通用型語言,已經具有近二十年的發展歷史,成熟且穩定。

㈤ 怎麼用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 程序求助! 有兩個!求高手用題目的語言編兩個程序!

完全按照要求來的:

====== q1.py ======
#coding: utf-8
def isPrime(n):
for x in range(2, n):
if n % x == 0:
return False
return True

def main():
num = raw_input("Please enter an integer ").strip()
try:
num = int(num)
except:
print "Invalid input, exit."
return
if isPrime(num):
print "%s is a prime number" % num
else:
print "%s is not a prime number" % num

if __name__ == "__main__":
main()

====== q2.py ======
#coding: utf-8
import random

QS_COUNT = 0
CORRECT_COUNT = 0
LEVELS = [11, 21, 51]

def make_qs(level = 1):
max_num = LEVELS[level-1]
s = [random.randrange(max_num) for x in range(2)]
return " + ".join(map(str, s)), str(sum(s))

if __name__ == "__main__":
while True:
level = raw_input("Choose a level(1,2,3): ").strip()
if level.isdigit() and int(level) in range(1, 4):
level = int(level)
print "Level %s start." % level
break
else:
print "Invalid level!"

while True:
QS_COUNT += 1
qs = make_qs(level)
print "%s: %s" % (QS_COUNT, qs[0])
if raw_input("answer:").strip() == qs[1]:
print "Correct!"
CORRECT_COUNT += 1
else:
print "Incorrect."

if raw_input("Continue?:").strip() != "yes":
break
print "Number of Correct Answers: %s Percentage: %s %%" % (CORRECT_COUNT, float(CORRECT_COUNT)/QS_COUNT*100)

㈧ Python編程網頁爬蟲工具集介紹

【導語】對於一個軟體工程開發項目來說,一定是從獲取數據開始的。不管文本怎麼處理,機器學習和數據發掘,都需求數據,除了通過一些途徑購買或許下載的專業數據外,常常需求咱們自己著手爬數據,爬蟲就顯得格外重要,那麼Python編程網頁爬蟲東西集有哪些呢?下面就來給大家一一介紹一下。

1、 Beautiful Soup

客觀的說,Beautifu Soup不完滿是一套爬蟲東西,需求協作urllib運用,而是一套HTML / XML數據分析,清洗和獲取東西。

2、Scrapy

Scrapy相Scrapy, a fast high-level screen scraping and web crawling framework
for
Python.信不少同學都有耳聞,課程圖譜中的許多課程都是依託Scrapy抓去的,這方面的介紹文章有許多,引薦大牛pluskid早年的一篇文章:《Scrapy
輕松定製網路爬蟲》,歷久彌新。

3、 Python-Goose

Goose最早是用Java寫得,後來用Scala重寫,是一個Scala項目。Python-Goose用Python重寫,依靠了Beautiful
Soup。給定一個文章的URL, 獲取文章的標題和內容很便利,用起來非常nice。

以上就是Python編程網頁爬蟲工具集介紹,希望對於進行Python編程的大家能有所幫助,當然Python編程學習不止需要進行工具學習,還有很多的編程知識,也需要好好學起來哦,加油!

㈨ 如何用 python 分析網站日誌

日誌的記錄

Python有一個logging模塊,可以用來產生日誌。
(1)學習資料
http://blog.sina.com.cn/s/blog_4b5039210100f1wv.html

http://blog.donews.com/limodou/archive/2005/02/16/278699.aspx
http://kenby.iteye.com/blog/1162698
http://blog.csdn.NET/fxjtoday/article/details/6307285
前邊幾篇文章僅僅是其它人的簡單學習經驗,下邊這個鏈接中的內容比較全面。

http://www.red-dove.com/logging/index.html

(2)我需要關注內容
日誌信息輸出級別
logging模塊提供了多種日誌級別,如:NOTSET(0),DEBUG(10),
INFO(20),WARNING(30),WARNING(40),CRITICAL(50)。
設置方法:
logger = getLogger()
logger.serLevel(logging.DEBUG)

日誌數據格式
使用Formatter設置日誌的輸出格式。
設置方法:
logger = getLogger()
handler = loggingFileHandler(XXX)
formatter = logging.Formatter("%(asctime)s %(levelname) %(message)s","%Y-%m-%d,%H:%M:%S")

%(asctime)s表示記錄日誌寫入時間,"%Y-%m-%d,%H:%M:%S「設定了時間的具體寫入格式。
%(levelname)s表示記錄日誌的級別。
%(message)s表示記錄日誌的具體內容。

日誌對象初始化
def initLog():
logger = logging.getLogger()
handler = logging.FileHandler("日誌保存路徑")
formatter = logging.Formatter("%(asctime)s %(levelname) %(message)s","%Y-%m-%d,%H:%M:%S")
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel

寫日誌
logging.getLogger().info(), logging.getLogger().debug()......

2. 日誌的分析。
(1)我的日誌的內容。(log.txt)
2011-12-12,12:11:31 INFO Client1: 4356175.0 1.32366309133e+12 1.32366309134e+12
2011-12-12,12:11:33 INFO Client1: 4361320.0 1.32366309334e+12 1.32366309336e+12
2011-12-12,12:11:33 INFO Client0: 4361320.0 1.32366309389e+12 1.32366309391e+12
2011-12-12,12:11:39 INFO Client1: 4366364.0 1.32366309934e+12 1.32366309936e+12
2011-12-12,12:11:39 INFO Client0: 4366364.0 1.32366309989e+12 1.32366309991e+12
2011-12-12,12:11:43 INFO Client1: 4371416.0 1.32366310334e+12 1.32366310336e+12
2011-12-12,12:11:43 INFO Client0: 4371416.0 1.32366310389e+12 1.32366310391e+12
2011-12-12,12:11:49 INFO Client1: 4376450.0 1.32366310934e+12 1.32366310936e+12
我需要將上述內容逐行讀出,並將三個時間戳提取出來,然後將其圖形化。

(2) 文件操作以及字元串的分析。
打開文件,讀取出一行日誌。
file = file("日誌路徑",「r」)
while True:
line = file.readline()
if len(len) == 0:
break;
print line
file.close()

從字元串中提取數據。
字元串操作學習資料:

http://reader.you.com/sharelite?itemId=-4646262544179865983&method=viewSharedItemThroughLink&sharedBy=-1137845767117085734
從上面展示出來的日誌內容可見,主要數據都是用空格分隔,所以需要使用字元串的
split函數對字元串進行分割:
paraList = line.split(),該函數默認的分割符是空格,返回值為一個list。
paraList[3], paraList[4], paraList[5]中分別以字元串形式存儲著我需要的時間戳。

使用float(paraList[3])將字元串轉化為浮點數。
(3)將日誌圖形化。
matplotlib是python的一個繪圖庫。我打算用它來將日誌圖形化。
matplotlib學習資料。
matplotlib的下載與安裝:
http://yexin218.iteye.com/blog/645894
http://blog.csdn.Net/sharkw/article/details/1924949

對matplotlib的宏觀介紹:
http://apps.hi..com/share/detail/21928578
對matplotlib具體使用的詳細介紹:

http://blog.sina.com.cn/s/blog_4b5039210100ie6a.html
在matplotlib中設置線條的顏色和形狀:
http://blog.csdn.net/kkxgx/article/details/python

如果想對matplotlib有一個全面的了解,就需要閱讀教程《Matplotlib for Python developers》,教程下載地址:
http://download.csdn.net/detail/nmgfrank/4006691

使用實例
import matplotlib.pyplot as plt

listX = [] #保存X軸數據
listY = [] #保存Y軸數據
listY1 = [] #保存Y軸數據

file = file("../log.txt","r")#打開日誌文件

while True:
line = file.readline()#讀取一行日誌
if len(line) == 0:#如果到達日誌末尾,退出
break
paraList = line.split()
print paraList[2]
print paraList[3]
print paraList[4]
print paraList[5]
if paraList[2] == "Client0:": #在坐標圖中添加兩個點,它們的X軸數值是相同的
listX.append(float(paraList[3]))
listY.append(float(paraList[5]) - float(paraList[3]))
listY1.append(float(paraList[4]) - float(paraList[3]))

file.close()

plt.plot(listX,listY,'bo-',listX,listY1,'ro')#畫圖
plt.title('tile')#設置所繪圖像的標題
plt.xlabel('time in sec')#設置x軸名稱
plt.ylabel('delays in ms'')#設置y軸名稱

plt.show()

㈩ 怎樣用python爬新浪微博大V所有數據

{
"ok": 1,
"count": 37227,
"cards": [{
"mod_type": "mod\/pagelist",
"previous_cursor": "",
"next_cursor": "",
"card_group": [{
"card_type": 9,
"mblog": {
"created_at": "08-27 19:40",
"id": 3880537095622460,
"mid": "3880537095622460",
"idstr": "3880537095622460",
"text": "一切都是最好的安排",
"source_allowclick": 0,
"source_type": 1,
"source": "微博 weibo.com",
"favorited": false,
"pic_ids": [""],
"thumbnail_pic": "http:\/\/ww4.sinaimg.cn\/thumbnail\/.jpg",
"bmiddle_pic": "http:\/\/ww4.sinaimg.cn\/bmiddle\/.jpg",
"original_pic": "http:\/\/ww4.sinaimg.cn\/large\/.jpg",
"user": {},
"reposts_count": 230,
"comments_count": 25,
"attitudes_count": 227,
"mlevel": 0,
"visible": {},
"biz_feature": 0,
"userType": 0,
"mblogtype": 0,
"created_timestamp": 1440675603,
"bid": "CxN8xnAEQ",
"pics": [{}],
"like_count": 227,
"attitudes_status": 0
}
},
後面還有好多好多好多好多好多好多好多好多好多好多好多好多的內容。。。我刪掉了後面的部分
]
}]
}

閱讀全文

與新浪level2python相關的資料

熱點內容
法國小女生電影 瀏覽:306
反編譯本地運算游戲 瀏覽:565
阿里雲伺服器被攻擊了多久恢復 瀏覽:292
我的孝順女兒電影 瀏覽:597
翠微居txt下載 瀏覽:394
tom快播 瀏覽:662
換硬幣演算法遞歸 瀏覽:122
四級電影推薦 瀏覽:847
女主手臂處有射精管理局臂章的電影 瀏覽:328
從哪找韓國電影 瀏覽:313
pdf轉換成ppt如何轉換 瀏覽:146
國內越南戰爭的電影 瀏覽:246
台灣好看的倫理電影 瀏覽:525
外遇的妻子2李采潭 瀏覽:954
365電影網站免費 瀏覽:785
網頁看電影不卡的網站 瀏覽:528
山西壓縮天然氣集團晉城有限公司 瀏覽:732
穿越到紅軍長征時期開超市 瀏覽:667
免費看電影無廣告網站 瀏覽:579
十降頭師電影 瀏覽:928