
Patrick B. answered 02/25/21
Math and computer tutor/teacher
There are compiler errors that need to be
addressed. Parenthesis are required in the
print statement and the indentation is in quetion
for each of these exercises.
Part A:
Actually it is a compiler error!
The parenthesis are missing around count+1,
the argument to the print statement...
The indentation is also in question.
Once added the code fragement becomes:
for count in range(5):
print(count+1)
which produces output:
1
2
3
4
5
note that range(5) is actually the set {0,1,2,3,4};
to which one is added to get the output. The loop
is zero based, which means it stops ONE LESS than
the parameter of 5.
So range(10) as an addition example is 0,1,2,3,4,5,6,7,8,9
and range(100) is 0,1,2,3,....,97,98,99
---------------------------------------------------
Part B:
again, parenthesis are needed and the indentation is in question.
once fixed the output shall be:
1
2
3
because it is instructed to stop at 1 and end at 4-1=3.
Part C:
Barring the compiler errors, the RANGE statement says
to begin at 1, end at 5 increasing by 2. so the output is:
1
3
5
Part D:
Again, barring the compiler errors, once fixed, the
RANGE statement instructs to begin at 6, stops at 2,
a DECREASES by 1.
the output is:
6
5
4
3
2
(1)
for count in range(100):
print ("your name")
(3) it's the loop counter
(1)
for count in range(128):
print (str(count) + " = " + str(chr(count)))
(1)
for count in range(128):
print (str(count) + " = " + str(chr(count)))
print("------ printables only ----------------")
for count in range(32,127):
print (str(count) + " = " + str(chr(count)))
(1)
# A FUNCTION returns values; A variable does not return
# values, but rather STORES a value in memory....
# anyways....
def AsciiDump(strbuff):
n = len(strbuff)
print("-----------------------------------------------")
for i in range(n):
print(str(strbuff[i]) + " = " + str(ord(strbuff[i])))
testString = "The quick brown fox jumped over the lazy dogs."
AsciiDump(testString)
testString="THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS."
AsciiDump(testString)