Skip to content

Commit 1bf1e30

Browse files
authored
Merge pull request #8 from Code-by-practice/develop
Develop
2 parents 3c40743 + 072437f commit 1bf1e30

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

codes/session_2/condition.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Open terminal > python3 condition.py
2+
# Start typing below commands and see the output
3+
4+
x = int(input('Please enter an integer: '))
5+
6+
if x < 0:
7+
print(str(x) + ' is a negative number')
8+
elif x == 0:
9+
print(str(x) + ' is zero')
10+
else:
11+
print(str(x) + ' is a positive number')

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')

codes/session_2/loop.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Open terminal > python3 loop.py
2+
# Start typing below commands and see the output
3+
4+
animals = ['cat', 'dog', 'racoon']
5+
for a in animals:
6+
print(a, len(a))
7+
8+
print('\n')
9+
10+
for i in range(5):
11+
print(i)
12+
13+
print('\n')
14+
15+
for i in range(5, 10):
16+
print(i)
17+
18+
print('\n')
19+
20+
# (range start, range end, step)
21+
for i in range(0, 10, 3):
22+
print(i)
23+
24+
print('\n')
25+
26+
for i in range(-10, -100, -30):
27+
print(i)
28+
29+
print('\n')
30+
31+
a = ['My', 'name', 'is', 'Ashwin']
32+
for i in range(len(a)):
33+
print(i, a[i])
34+
35+
print('\n')

0 commit comments

Comments
 (0)