Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gmolveau
GitHub Repository: gmolveau/python_full_course
Path: blob/master/exercices/sponge_cli.py
305 views
1
# sponge_cli.py
2
import random
3
import click
4
5
6
def convert(sentence):
7
sentence = sentence.lower()
8
r = []
9
for carac in sentence:
10
if carac.isspace():
11
r.append(carac)
12
else:
13
if random.random() < 0.5: # 50% chance
14
r.append(carac.upper())
15
else:
16
r.append(carac)
17
return ''.join(r)
18
19
20
@click.command()
21
@click.argument('sentence')
22
def meme(sentence):
23
'''converts a sentence to a spongebob meme'''
24
meme_sentence = convert(sentence)
25
print(meme_sentence)
26
27
28
if __name__ == '__main__':
29
meme()
30
31