Skip to content

Commit 7f3962b

Browse files
Devon JueDevon Jue
Devon Jue
authored and
Devon Jue
committed
added comments to the rest of the files
1 parent 7f0c574 commit 7f3962b

5 files changed

+67
-1
lines changed

sampleimport.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
# import command line argument reader 'argv' from the 'sys' python module
12
from sys import argv
3+
4+
# takes the two arguments after the 'python' command,
5+
# and assigns to the variables 'script' and 'user_name'
26
script, user_name = argv
7+
8+
# assigns the string with an arrow and space to the variable 'prompt'
39
prompt = '> '
10+
11+
# user_name, the second argument, and 'sampleimport.py' replace %s in the order listed
412
print "Hi %s, I'm the %s script." % (user_name, script)
513
print "I'd like to ask you a few questions."
14+
15+
# replaces %s with the variable user_name and prints
616
print "Do you like me %s?" % user_name
17+
18+
# prints '> ' and allows user to input a value, assigns user input to the 'likes' variable
719
likes = raw_input(prompt)
20+
21+
# repeats the process above two more times
822
print "Where do you live %s?" % user_name
923
lives = raw_input(prompt)
1024
print "What kind of computer do you have?"
1125
computer = raw_input(prompt)
26+
27+
# takes the last three user inputs in order and inserts into the last print statement, replacing %r
1228
print """
1329
Alright, so you said %r about liking me.
1430
You live in %r. Not sure where that is.

sampleinput.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
# import command line argument reader 'argv' from the 'sys' python module
12
from sys import argv
3+
4+
# takes the four arguments after the 'python' command,
5+
# and assigns to the variables 's', 'f', 'ss', and 't'
26
s,f,ss,t=argv
7+
8+
# prints the four arguments on separate lines with text
39
print "the script is" , s
410
print "var1 1 is" , f
511
print "var 2 is" , ss

sampleloops.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
# assigns numbers 1 through 3 to an array
12
arr=[1,2,3]
3+
4+
# assigns three names to an array
25
arrstr=["ashu" , "himu" , "piyu"]
6+
7+
# loops through each number from the number array, and prints the number
38
for num in arr:
49
print "numbers are %d" %num
10+
11+
# loops through each name from the name array, and prints the name
512
for name in arrstr:
613
print "names are %s" %name
14+
15+
# initializes an empty array
716
arrinput=[]
17+
18+
# asks the user for a input four times and pushes inputs into an array
819
for i in range(0,4):
920
print "enter element number %d" %i
1021
number = raw_input("> ")
1122
arrinput.append(number)
23+
24+
# loops through the input array and prints each input
1225
for inp in arrinput:
1326
print "elements are %r" %inp

sampleprint.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
# prints an empty space since comments are ignored
12
print #"Hello World!"
3+
4+
# prints the following strings and separate lines
25
print "Hello Again"
36
print "I like typing this."
47
print "This is fun."
58
print 'Yay! Printing.'
69
print "I'd much rather you 'not'."
710
print 'I "said" do not touch this.'
11+
12+
# prints the boolean value of this mathematical comparison
813
print 3 + 2 < 5 - 7
14+
15+
# assigning numerical values to variables
916
cars = 100
1017
space_in_a_car = 4.0
1118
drivers = 30
1219
passengers = 90
20+
21+
# performing mathematical operations on the variables above,
22+
# and assigning the answers to new variables
1323
cars_not_driven = cars - drivers
1424
cars_driven = drivers
1525
carpool_capacity = cars_driven * space_in_a_car
1626
average_passengers_per_car = passengers / cars_driven
27+
28+
# the new variables are printed on separate lines
1729
print "We need to put about", average_passengers_per_car, "in each car."
1830
print "We have", passengers, "to carpool today."
1931
print "There will be", cars_not_driven, "empty cars today."

samplewhile.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,33 @@
66

77
# SAMPLE CODE
88

9+
# initialize the while iterator to 0
910
i = 0
11+
12+
# initialze empty numbers array
1013
numbers = []
14+
15+
# keep running this while loop as long as 'i' is less than 6
1116
while i < 6:
17+
18+
# prints the value of i at the beginning of the loop
1219
print "At the top i is %d" % i
20+
21+
# adds the number i to the number array
1322
numbers.append(i)
23+
24+
# increase the number i by 1
1425
i = i + 1
26+
27+
# prints the current numbers array
1528
print "Numbers now: ", numbers
29+
30+
# prints the value of i at the end of the loop
1631
print "At the bottom i is %d" % i
17-
print "The numbers: "
32+
33+
# prints the numbers of the numbers array,
34+
# every value of i during the loop before it exited (0 through 5)
35+
# since the while loop exited when i reached 6
36+
print "The numbers: "
1837
for num in numbers:
1938
print num

0 commit comments

Comments
 (0)