Skip to content

Commit 072437f

Browse files
author
ashegde
committed
feat(examples): function and arguments
1 parent bfc9ec0 commit 072437f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

codes/session_2/default.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Open terminal > python3 default.py
2+
# Start typing below commands and see the output
3+
4+
# Function with default values for arguments, and while loop examples
5+
# Note: The default value is evaluated only once.
6+
7+
def askme(prompt, retries=3, reminder='Invalid response, please try again!'):
8+
while True:
9+
ok = input(prompt)
10+
11+
if ok in ('y', 'yes'):
12+
return True
13+
14+
if ok in ('n', 'no'):
15+
return False
16+
17+
retries = retries - 1
18+
19+
if retries < 0:
20+
raise ValueError('System is auto locked!')
21+
22+
print(reminder)
23+
24+
askme('Are you sure you want to quit? ')
25+
26+
27+
# Annotations example
28+
def hello(name: str) -> str:
29+
print('Annotations: ', hello.__annotations__)
30+
31+
hello('Ashwin')

0 commit comments

Comments
 (0)