- 论坛徽章:
- 1
|
本帖最后由 jordie 于 2011-05-31 14:39 编辑
最近没心思上班,一直拿不定主意,就用PYTHON写了一个命运选择器:- #!/usr/bin/python
- import random
- print '################################################################################'
- print '''Welcome to mychoice! If you hard to make a decision,Just try this MyChoice!'''
- print '################################################################################'
- choice1 = raw_input('Input one of you choice:')
- choice2 = raw_input('Input the second choice:')
- counttimes = raw_input('Input the times you want to count:')
- choice1_times = 0
- choice2_times = 0
- for i in range(0,int(counttimes)):
- if random.choice([choice1,choice2]) == choice1:
- choice1_times += 1
- else:
- choice2_times += 1
- print '%s is %s times, and %s is %s times' %(choice1,choice1_times,choice2,choice2_times)
- choices={choice1:choice1_times,choice2:choice2_times}
- print '*******************************************'
- print 'You choice is',max(choices.iterkeys(),key = lambda k: choices[k])
- print '*******************************************'
复制代码- ################################################################################
- Welcome to mychoice! If you hard to make a decision,Just try this MyChoice!
- ################################################################################
- Input one of you choice:staying
- Input the second choice:leaving
- Input the times you want to count:10000000
- staying is 4999691 times, and leaving is 5000309 times
- *******************************************
- You choice is leaving
- *******************************************
复制代码 |
|