Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
4aa2cdcb
Commit
4aa2cdcb
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
c83e7cf7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/ThreeWayConditional.ipynb
+70
-0
70 additions, 0 deletions
CodeExamples/ThreeWayConditional.ipynb
with
70 additions
and
0 deletions
CodeExamples/ThreeWayConditional.ipynb
0 → 100644
+
70
−
0
View file @
4aa2cdcb
{
"cells": [
{
"cell_type": "markdown",
"id": "e477673e",
"metadata": {},
"source": [
"# Three Way Conditional"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0274b5d",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
" Three way conditional example\n",
"\"\"\"\n",
"\n",
"import math\n",
"\n",
"def main():\n",
" a = float(input(\"Give a float : \"))\n",
" if a > 4.0 :\n",
" # Inside if\n",
" b = 4.0 - math.sqrt(a)\n",
" a = 2.0*(b - 3.0)\n",
" print(\"if statements executed\")\n",
" elif a > 0 :\n",
" # Inside else is\n",
" b = 1.0 + math.sqrt(a)\n",
" a = (b - 1.0)\n",
" print(\"elif statements executed\")\n",
" else :\n",
" # Inside else\n",
" b = 4.0 - 3.0*math.sqrt(-a)\n",
" a = 7.0*(b - 3.0)\n",
" print(\"else statements executed\")\n",
"\n",
" # Outside conditional\n",
" print(\"The value of a is : \" + str(a) + \" and b is : \" + str(b))\n",
"\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:e477673e tags:
# Three Way Conditional
%% Cell type:code id:d0274b5d tags:
```
python
"""
Three way conditional example
"""
import
math
def
main
():
a
=
float
(
input
(
"
Give a float :
"
))
if
a
>
4.0
:
# Inside if
b
=
4.0
-
math
.
sqrt
(
a
)
a
=
2.0
*
(
b
-
3.0
)
print
(
"
if statements executed
"
)
elif
a
>
0
:
# Inside else is
b
=
1.0
+
math
.
sqrt
(
a
)
a
=
(
b
-
1.0
)
print
(
"
elif statements executed
"
)
else
:
# Inside else
b
=
4.0
-
3.0
*
math
.
sqrt
(
-
a
)
a
=
7.0
*
(
b
-
3.0
)
print
(
"
else statements executed
"
)
# Outside conditional
print
(
"
The value of a is :
"
+
str
(
a
)
+
"
and b is :
"
+
str
(
b
))
main
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment