-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-puzzles.py
More file actions
53 lines (48 loc) · 1.31 KB
/
string-puzzles.py
File metadata and controls
53 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# FizzBuzz
# Input: Number to generate fizzbuzz to
# Output: None. Prints to console directly
def fizz_buzz(x):
fb = lambda n, m : n % m
for i in range(x + 1):
if fb(i, 15) == 0:
print("FizzBuzz")
elif fb(i, 5) == 0:
print("Buzz")
elif fb(i, 3) == 0:
print("Fizz")
else:
print(i)
# Palendrome
# Input: A single word as string
# Output: Boolean representing whether or not the word is a palendrome
def palendrome(word):
reverse = word[::-1]
if reverse == word:
return True
else:
return False
# Word Count
# Input: a string
# Output: Number of words in string
def word_count(text):
count = 1
for c in text:
if c == ' ':
count += 1
return count
# INPUT FUNCTIONS
# Get Help
# Lists all commands that are available for the user
def get_help():
commands = {
'fizzbuzz' : 'Initiate the fizz buzz module',
'fizz' : 'Initiate the fizz buzz module. Alias for fizzbuzz',
'help' : 'Print off a list of commands',
'h' : 'Print off a list of commands. Alias for help',
'quit' : 'Terminates the program',
'q' : 'Terminates the program. Alias for quit'
}
print()
for key in commands:
print(key + ': ' + commands[key])
print()