本文目錄一覽:
- 1、如何用python實現網路上的自動投票功能
- 2、如何用Python來做一個投票app?
- 3、python新手求助 寫一個投票的代碼 def vote() 有三種,yes,no,abstain
- 4、python如何編一個投票系統
如何用python實現網路上的自動投票功能
網路投票大都採用post方法,因此我們可以分析post的url,對具體的post參數進行分析,通過requests模塊,進行提交就行了。需要注意的是大部分網站可能存在ip地址限制,或者瀏覽器限制等情況,所以需要設計代理和ua列表進行投票,避免被屏蔽。
如何用Python來做一個投票app?
app?你要做手機上的還是網頁的?
推薦你看《深入淺出python》的後面幾章,講cgi和android的。如果你是要做網頁的,可以看web.py或者django
python新手求助 寫一個投票的代碼 def vote() 有三種,yes,no,abstain
def vote(stra):
yesstr=[‘yes’,’y’]
nostr=[‘no’,’n’]
abstainedstr=[‘abstained’,’a’]
count=0
yescount=0
stra=stra.replace(‘,’,’ ‘)
for i in stra.split():
lowerstr=i.lower()
if lowerstr in yesstr:
yescount+=1
count+=1
elif lowerstr in nostr:
count+=1
if yescount==count:
return ‘proposal passes unanimously’
if yescount*1.0/count=2.0/3.0:
return ‘proposal passes with super majority’
if yescount*1.0/count=0.5:
return ‘proposal passes with simple majority’
return ‘proposal fails’
if __name__==’__main__’:
stra=raw_input(‘Enter the yes,no,abstained votes one by one and the press enter:\n’)
print vote(stra)
python如何編一個投票系統
LI = [‘張三’,’李四’,’劉五’]
def inputs(prompt, selectlist, eof=’EOF’):
while True:
choice = raw_input(prompt)
if choice == eof:
break
elif choice in selectlist:
yield choice
else:
print “only in %s” % selectlist
collects = map(None, inputs(“投票”, LI, eof=’投票結束’))
# by dict
counter = {}
for name in collects:
counter[name] = counter.get(name,0)+1
for name, c in sorted(counter.items(), key=lambda x:x[1], reverse=True):
print name, c
# by collections.Counter
import collections
counter = collections.Counter(collects)
for name, c in counter.most_common(10):
print name, c
原創文章,作者:YGWIF,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/315975.html