
Patrick B. answered 03/08/21
Math and computer tutor/teacher
a) There are syntax and compile errors...
In must be lowercase, parenthesis are required
for print statements
The correct statement for this for loop is:
for count In range(5):
print count + 1
Once corrected the output is:
1
2
3
4
5
b) Again, there is a compiler error because parenthesis
are required for print statement.
The correct statement for this for loop is:
for count in range(1,4):
print count
c) Same error, print statement requires parenthesis....
The corrected for loop is:
for count in range(1,6,2):
print(count)
The output is:
1
3
5
d) Same error, print statement requires parenthesis...
THe corrected for loop is :
for count in range(6,1,-1):
print (count)
The output is:
6
5
4
3
2
#Prints your name 100 times
for count in range(100):
print ("Your name")
#Displays ASCII Table
print(" -----------------------------------")
print(" the 1st 128 ascii values...........")
print(" ascii value character ")
for asciiLoop in range(128):
print(" " +str(asciiLoop) + " " + chr(asciiLoop) )
print(" -----------------------------------")
print(" the 1st 128 ascii values...........")
for asciiLoop in range(256):
print( " " + str(asciiLoop) + " " + chr(asciiLoop) )
#############################################################
ASCII DUMP
#############################################################
import random
def testString():
n = random.randint(0,25)
strReturnStr = " "
for i in range(n):
asciiValue = 0
while (int(asciiValue)<32):
asciiValue = random.randint(32,127)
strReturnStr = strReturnStr + chr(asciiValue)
return(strReturnStr)
###################################################
def asciiDump(inbuff):
n = len(inbuff)
print(" Character Ascii Value ")
for i in range(n):
ch = inbuff[i]
print( ch + " " + str(ord(ch)))
####################################################
strBuffStr = testString()
asciiDump(strBuffStr)