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
386c74aa
Commit
386c74aa
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Replace RangeLooptoList.ipynb
parent
10df51e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/RangeLooptoList.ipynb
+20
-7
20 additions, 7 deletions
CodeExamples/RangeLooptoList.ipynb
with
20 additions
and
7 deletions
CodeExamples/RangeLooptoList.ipynb
+
20
−
7
View file @
386c74aa
...
...
@@ -5,7 +5,7 @@
"id": "d6f58633",
"metadata": {},
"source": [
"# R
eading and Printing Floats Main
"
"# R
ange Loop to List
"
]
},
{
...
...
@@ -16,17 +16,30 @@
"outputs": [],
"source": [
"\"\"\"\n",
" Starter Python programm to read in and print a floating point number\n",
" Example to demonstrate a range loop to write theta and cos theta\n",
" to a list\n",
"\"\"\"\n",
"\n",
"import math\n",
"\n",
"def main():\n",
" \"\"\" Read in a number and print it\n",
" \"\"\"\n",
" x = float(input(\"Type in a floating point number : \"))\n",
"\n",
" # Print it out\n",
" print(\"The number types was : \" + str(x))\n",
" n_point = 50\n",
" theta_data = [] # empty list \n",
" cos_data = [] # empty list\n",
"\n",
"\n",
" for i in range(0,n_point):\n",
" theta = 2.0*math.pi*i/n_point # Set theta\n",
" cos = math.cos(theta)\n",
" theta_data.append(theta) # Add values to list\n",
" cos_data.append(cos)\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()"
]
...
...
%% Cell type:markdown id:d6f58633 tags:
# R
eading and Printing Floats Main
# R
ange Loop to List
%% Cell type:code id:c2f2695d tags:
```
python
"""
Starter Python programm to read in and print a floating point number
Example to demonstrate a range loop to write theta and cos theta
to a list
"""
import
math
def
main
():
"""
Read in a number and print it
"""
x
=
float
(
input
(
"
Type in a floating point number :
"
))
# Print it out
print
(
"
The number types was :
"
+
str
(
x
))
n_point
=
50
theta_data
=
[]
# empty list
cos_data
=
[]
# empty list
for
i
in
range
(
0
,
n_point
):
theta
=
2.0
*
math
.
pi
*
i
/
n_point
# Set theta
cos
=
math
.
cos
(
theta
)
theta_data
.
append
(
theta
)
# Add values to list
cos_data
.
append
(
cos
)
# 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