Skip to content
Snippets Groups Projects
Commit 0337349a authored by msyamkumar's avatar msyamkumar
Browse files

Removing checkpoints

parent f758fd59
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
def absolute_v1(x):
return (x ** 2) ** 0.5
```
%% Cell type:code id: tags:
``` python
print(absolute_v1(-4))
print(absolute_v1(4))
```
%% Output
4.0
4.0
%% Cell type:code id: tags:
``` python
def absolute_v2(x):
if x < 0:
x = -x
return x
```
%% Cell type:code id: tags:
``` python
print(absolute_v2(-4))
print(absolute_v2(4))
```
%% Output
4
4
%% Cell type:code id: tags:
``` python
def absolute_v3(x):
if x < 0:
return -x
else:
return x
```
%% Cell type:code id: tags:
``` python
print(absolute_v3(-4))
print(absolute_v3(4))
```
%% Output
4
4
%% Cell type:code id: tags:
``` python
def absolute_v4(x):
if x < 0:
return -x
# else: (Implicit case)
return x
```
%% Cell type:code id: tags:
``` python
print(absolute_v4(-4))
print(absolute_v4(4))
```
%% Output
4
4
%% Cell type:code id: tags:
``` python
def f(x):
if x < -2:
return 2
else:
if x < 0:
#Does this run when x is -10? No, because exactly
#-10 satifies the if condition, hence elif will not
#be evaluated for -10 (exactly one branch gets executed)
return -x
else:
return int(x)
```
%% Cell type:code id: tags:
``` python
print(f(-10))
print(f(-20))
print(f(30.5))
print(f(-1))
print(f(3))
print(f(10))
```
%% Output
2
2
30
1
3
10
%% Cell type:code id: tags:
``` python
def f(x):
if x < -2:
return 2
elif x < 0:
return -x
else:
return int(x)
```
%% Cell type:code id: tags:
``` python
print(f(-10))
print(f(-20))
print(f(30.5))
print(f(-1))
print(f(3))
print(f(10))
```
%% Output
2
2
30
1
3
10
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment