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
dc1b2df9
Commit
dc1b2df9
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
fd5e5d2c
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/WhileLooptoList.ipynb
+70
-0
70 additions, 0 deletions
CodeExamples/WhileLooptoList.ipynb
with
70 additions
and
0 deletions
CodeExamples/WhileLooptoList.ipynb
0 → 100644
+
70
−
0
View file @
dc1b2df9
{
"cells": [
{
"cell_type": "markdown",
"id": "15c99cef",
"metadata": {},
"source": [
"# While Loop to List"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a90d92d5",
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
" Example to demonstrate a while loop to write theta and cos theta\n",
" to a list\n",
"\"\"\"\n",
"\n",
"import math\n",
"\n",
"def main():\n",
" n_point = 50\n",
" delta_theta = 2.0*math.pi/n_point # theta increment\n",
" theta = 0.0 # theta start\n",
" theta_data = [] # empty list \n",
" cos_data = [] # empty list\n",
"\n",
"\n",
" while theta < 2.0*math.pi: # while loop\n",
" cos = math.cos(theta)\n",
" theta_data.append(theta) # Add values to list\n",
" cos_data.append(cos)\n",
" theta += delta_theta # increment theta\n",
"\n",
" # Do a default print (not very tidy output, replace this and \n",
" # a loop and make it nicer)\n",
" print(str(theta_data))\n",
" print(str(cos_data))\n",
"\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:15c99cef tags:
# While Loop to List
%% Cell type:code id:a90d92d5 tags:
```
python
"""
Example to demonstrate a while loop to write theta and cos theta
to a list
"""
import
math
def
main
():
n_point
=
50
delta_theta
=
2.0
*
math
.
pi
/
n_point
# theta increment
theta
=
0.0
# theta start
theta_data
=
[]
# empty list
cos_data
=
[]
# empty list
while
theta
<
2.0
*
math
.
pi
:
# while loop
cos
=
math
.
cos
(
theta
)
theta_data
.
append
(
theta
)
# Add values to list
cos_data
.
append
(
cos
)
theta
+=
delta_theta
# increment theta
# Do a default print (not very tidy output, replace this and
# a loop and make it nicer)
print
(
str
(
theta_data
))
print
(
str
(
cos_data
))
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