Skip to content

Commit 64422d5

Browse files
committed
Added class 2
Class 2 needs some attention. It does not yet have a homework assignment, and I’m not sure that it’s at the appropriate level.
1 parent 64a3d61 commit 64422d5

File tree

6 files changed

+165
-1
lines changed

6 files changed

+165
-1
lines changed

Python Syllabus.pdf

650 Bytes
Binary file not shown.

Python Syllabus.tex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ \section{Second Class - Scripting}
9393
\subsection{Class expectations}
9494

9595
\begin{enumerate}
96-
\item Fill in expectations
96+
\item Understand what a script is and what it can do
97+
\item Run a script from the terminal
98+
9799
\end{enumerate}
98100

101+
Includes a PowerPoint to go through with students and a script to
102+
run.
103+
99104
%----------------------------------------------------------------------------------------
100105
%THIRD CLASS
101106
%----------------------------------------------------------------------------------------
39.7 KB
Binary file not shown.

class 2/example_script.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#! /usr/bin/env python
2+
3+
# This script will perform all the calculations we have done in class at once
4+
# It will also highlight some of the things you will learn to do by the end of the class
5+
6+
#this is how you can import packages that hold useful functions -- will be explained further
7+
import math
8+
import timeit
9+
10+
#DEFINE USER FUNCTIONS
11+
12+
#this is a function. When called in the script it will be run
13+
def perform_math(starting_number):
14+
num = starting_number*9
15+
16+
#this is a while loop and a control statement
17+
while (num >= 10):
18+
#creating a string and then splitting it
19+
mm = list(str(num))
20+
num = 0
21+
for num_pos in mm :
22+
num = num + int(num_pos)
23+
#End of the "nested" loop
24+
#end of the first loop
25+
26+
num = num-5
27+
28+
return num
29+
30+
#MAIN SCRIPT
31+
32+
start_time = timeit.default_timer()
33+
34+
#we will first open up a file for reading that is full of numbers
35+
num_file = open("ingredients_file.txt", "r")
36+
37+
#open up a file to write out the results
38+
out_file = open("results_file.txt", "w")
39+
40+
#I have put the contents of the file into what is called an array
41+
numbers = num_file.readlines()
42+
43+
#This is called a loop. This is how we can get every number in the file
44+
for i in range(len(numbers) ):
45+
46+
single_number = int(numbers[i]) #I am going through each number and making sure it is a number
47+
48+
#I am performing the math on that number and setting the result to a new variable
49+
new_output = perform_math(single_number)
50+
51+
#I am writing out the final output plus a new line character
52+
out_file.write(str(new_output) + "\n")
53+
54+
#Closing up the files
55+
out_file.close
56+
num_file.close
57+
58+
elapsed = timeit.default_timer() - start_time
59+
60+
print 'The time spent running the script is', elapsed, 'seconds'

class 2/ingredients_file.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
1
2+
2
3+
3
4+
4
5+
5
6+
6
7+
7
8+
8
9+
9
10+
10
11+
11
12+
12
13+
13
14+
14
15+
15
16+
16
17+
17
18+
18
19+
19
20+
20
21+
21
22+
22
23+
23
24+
24
25+
25
26+
26
27+
27
28+
28
29+
29
30+
30
31+
31
32+
32
33+
33
34+
34
35+
35
36+
36
37+
37
38+
38
39+
39
40+
40
41+
41
42+
42
43+
43
44+
44
45+
45
46+
46
47+
47
48+
48
49+
49
50+
50
51+
51
52+
52
53+
53
54+
54
55+
55
56+
56
57+
57
58+
58
59+
59
60+
60
61+
61
62+
62
63+
63
64+
64
65+
65
66+
66
67+
67
68+
68
69+
69
70+
70
71+
71
72+
72
73+
73
74+
74
75+
75
76+
76
77+
77
78+
78
79+
79
80+
80
81+
81
82+
82
83+
83
84+
84
85+
85
86+
86
87+
87
88+
88
89+
89
90+
90
91+
91
92+
92
93+
93
94+
94
95+
95
96+
96
97+
97
98+
98
99+
99

class 2/script_pres.pptx

49.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)