Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Coursework
Views: 52
import random def floatingvote(): r = random.random() if 0<=r<0.1: return "farleft" elif 0.1<=r<0.2: return "farright" elif 0.2<=r<0.5: return "centreleft" elif 0.5<=r<0.8: return "centreright" elif 0.8<=r<1: return "disenfranchised" def election(): votescast = 0 farleftvote = 0 farrightvote = 0 centreleftvote = 0 centrerightvote = 0 spoiltballots = 0 v = floatingvote() while votescast < 70000: v = floatingvote() if v == "farleft": farleftvote+=1 elif v == "farright": farrightvote+=1 elif v == "centreleft": centreleftvote+=1 elif v == "centreright": centrerightvote+=1 elif v == "disenfranchised": spoiltballots+=1 votescast+=1 print farleftvote print farrightvote print centreleftvote print centrerightvote print spoiltballots if farleftvote == max(farleftvote, farrightvote, centreleftvote, centrerightvote): print "the farleft party has won" elif farrightvote == max(farleftvote, farrightvote, centreleftvote, centrerightvote): print "the farright party has won" elif centreleftvote == max(farleftvote, farrightvote, centreleftvote, centrerightvote): print "the centreleft party has won" elif centrerightvote == max(farleftvote, farrightvote, centreleftvote, centrerightvote): print "the centreright party has won" election()
6997 6998 20978 21353 13674 the centreright party has won