Added Homework 04 - Strings
This commit is contained in:
parent
aad4e226c5
commit
be356ccb59
24 changed files with 315 additions and 0 deletions
31
homework/homework04/strings/stringToCharacters03.py
Normal file
31
homework/homework04/strings/stringToCharacters03.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import string
|
||||
|
||||
message = '''
|
||||
This program prints the Ascii codes for the whitespace.
|
||||
characters. These characters include the space, line return, tabs, etc.
|
||||
Printing the whitespace string does not appear to generate any results.
|
||||
Printing each character code is informative.
|
||||
'''
|
||||
message2 = '''
|
||||
Open a web browser. Go to https://www.ascii-code.com.
|
||||
Look up each of the codes from this program to determine
|
||||
their purpose.
|
||||
For example: 32 = space
|
||||
Look up the rest of the whitespace codes.
|
||||
'''
|
||||
|
||||
print(message)
|
||||
|
||||
|
||||
print(f"string.whitespace = {string.whitespace}")
|
||||
print(f"length of string.whitespace = {len(string.whitespace)}")
|
||||
# Since you cannot easily see the effect of whitespace characters,
|
||||
# we can print their numeric codes.
|
||||
|
||||
# Convert the string to a list of letters in the string.
|
||||
whiteSpaceCharactersList = list(string.whitespace)
|
||||
|
||||
for myCharacter in whiteSpaceCharactersList:
|
||||
print(f"{ord(myCharacter)}")
|
||||
|
||||
print(message2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue