简单的程序,统计四候选人的选举投票。 投票一次到达一个,其中投票四位候选人用数字表示, 最后在屏幕上打印出胜者。投票不算
有我的代码
candList = [0, 0, 0, 0]
while True:
print '1 for First Candidate'
print '2 for Second Candidate'
print '3 for Third Candidate'
print '4 for Fourth Candidate'
print '5 for Exit Poll'
cid = input('Enter Candidate Number to Vote: ')
if cid == 5:
break
candList[cid - 1]
vote = max(candList)
candidate = candList.index(vote) + 1
print 'Winner is Candidate', candidate, 'with', vote, 'Votes'
但问题投票不算.. 我给1名候选人3票,但最后打印
Result is : Winner is Candidate 1 with 0 Votes
'的eval(的raw_input())'?你是认真的吗? – Shashank
你期待'list [id - 1]'做什么,准确?!你是不是指'list [id] - = 1'?而**不要打电话给你自己的名单'列表**。 – jonrsharpe
使用'input'而不是'raw_input',并且没有'eval' – Morb