ROS Code
 All Classes Namespaces Files Functions Variables
fun.py
Go to the documentation of this file.
1 import random
2 
3 # Check if the user is a person by asking a simple maths question
4 
5 
6 def captcha():
7  tryanswer = ''
8  numbervalues = {
9  'one': 1,
10  'two': 2,
11  'three': 3,
12  'four': 4,
13  'five': 5,
14  'six': 6,
15  'seven': 7,
16  'eight': 8,
17  'nine': 9,
18  'ten': 10
19  }
20  numbertext = [
21  'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine',
22  'ten'
23  ]
24  if random.randint(1, 2) == 2:
25  parta = random.choice(numbertext)
26  else:
27  parta = random.randint(1, 10)
28  if random.randint(1, 2) == 2:
29  partb = random.choice(numbertext)
30  else:
31  partb = random.randint(1, 10)
32  tryanswer = input('CAPTCHA: What\'s ' + str(parta) + ' + ' + str(partb) +
33  '? Your Answer (In Digits): ')
34  if not bool(isinstance(parta, int)):
35  parta = numbervalues[parta]
36  if not bool(isinstance(partb, int)):
37  partb = numbervalues[partb]
38  try:
39  tryanswer = int(tryanswer)
40  except BaseException:
41  return False
42  return parta + partb == tryanswer
43 
44 
45 # Play paper scissors rock
46 
47 
48 def psrgame(choice):
49  choice = choice.lower()
50  choices = {
51  'paper': 1,
52  'papers': 1,
53  'scissor': 2,
54  'scissors': 2,
55  'rock': 3,
56  'rocks': 3
57  }
58  pcchoice = random.randint(0, 3)
59  if pcchoice == choices[choice]:
60  return 'Tie'
61  elif pcchoice < choices[choice]:
62  return 'Win'
63  elif pcchoice > choices[choice]:
64  return 'Loose'
65 
66 
67 # Roll a dice
68 
69 
70 def diceroll(dicecount=1, dicesize=6, alwayslist=False):
71  dicecount = int(dicecount)
72  if dicecount == 1 and alwayslist is False:
73  return random.randint(1, dicesize)
74  resultlist = []
75  for _ in range(dicecount):
76  resultlist.append(random.randint(1, dicesize))
77  return resultlist
78 
79 
80 # Play the yes-no game
81 
82 
83 def yesnogame(includemaybe=False):
84  if includemaybe is True:
85  maxnum = 3
86  else:
87  maxnum = 2
88  afternum = random.randint(1, maxnum)
89  if afternum == 1:
90  return "Yes"
91  elif afternum == 2:
92  return "No"
93  return "Maybe"
94 
95 
96 # Play the truth or lie game
97 
98 
100  truthnum = random.randint(1, 4)
101  if truthnum == 1:
102  return 'Truth'
103  elif truthnum == 2:
104  return 'Maybe'
105  elif truthnum == 3:
106  return 'Maybe'
107  return 'Lie'
108 
109 
110 # Show A Type Of Face
111 
112 
113 def face(facetype='smiley'):
114  facetype = facetype.lower()
115  if facetype == 'smiley':
116  print('😃')
117  elif facetype == 'straight':
118  print('😐')
119  elif facetype == 'sad':
120  print('☹')
def truthorliegame
Definition: fun.py:99
def captcha
Definition: fun.py:6
def psrgame
Definition: fun.py:48
def yesnogame
Definition: fun.py:83
def diceroll
Definition: fun.py:70
def face
Definition: fun.py:113