Skip to content

Commit 99dba21

Browse files
author
Joseph Pan
committed
trace line_count and current_line
1 parent 5556ad8 commit 99dba21

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Python2/ex20.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# Assign the first and the second arguments to the two variables
1010
script, input_file = argv
1111

12-
1312
# Define a function called print_call to print the whole contents of a
1413
# file, with one file object as formal parameter
1514
def print_all(f):
@@ -27,6 +26,8 @@ def rewind(f):
2726
# Define a function called print_a_line to print a line of the file,
2827
# with a integer counter and a file object as formal parameters
2928
def print_a_line(line_count, f):
29+
# Test whether two variables are carrying the same value
30+
print "line_count equal to current_line?:", (line_count == current_line)
3031
# print the number and the contents of a line
3132
print line_count, f.readline()
3233

@@ -53,15 +54,18 @@ def print_a_line(line_count, f):
5354

5455
# Set current line to 1
5556
current_line = 1
57+
print "current_line = %d" % current_line
5658
# Print current line by calling print_a_line function
5759
print_a_line(current_line, current_file)
5860

5961
# Set current line to 2 by adding 1
6062
current_line = current_line + 1
63+
print "current_line is equal to:%d" % current_line
6164
# Print current line by calling print_a_line function
6265
print_a_line(current_line, current_file)
6366

6467
# Set current line to 3 by adding 1
6568
current_line = current_line + 1
69+
print "current_line is equal to:%d" % current_line
6670
# Print current line by calling print_a_line function
6771
print_a_line(current_line, current_file)

Python3/ex20.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def rewind(f):
2626
# Define a function called print_a_line to print a line of the file,
2727
# with a integer counter and a file object as formal parameters
2828
def print_a_line(line_count, f):
29+
# Test whether two variables are carrying the same value
30+
print("line_count equal to current_line?:", (line_count == current_line))
2931
# print the number and the contents of a line
3032
print(line_count, f.readline())
3133

0 commit comments

Comments
 (0)