Added Homework 04 - Strings

This commit is contained in:
Edward Bigos 2026-11-03 10:54:55 -05:00
commit be356ccb59
24 changed files with 315 additions and 0 deletions

View file

@ -0,0 +1,18 @@
import string
# See https://docs.python.org/3/library/string.html
# These are some pre-defined character variables you can use.
print(f"string.ascii_letters = {string.ascii_letters}")
print(f"string.ascii_lowercase = {string.ascii_lowercase}")
print(f"string.ascii_uppercase = {string.ascii_uppercase}")
print(f"string.digits = {string.digits}")
print(f"string.hexdigits = {string.hexdigits}")
print(f"string.octdigits = {string.octdigits}")
print(f"string.punctuation = {string.punctuation}")
print(f"string.printable = {string.printable}")
print(f"string.whitespace = {string.whitespace}")
print(f"length of string.whitespace = {len(string.whitespace)}")

View file

@ -0,0 +1,17 @@
import string
message = '''
This program prints the Ascii codes for all the letters.
Notice the lower case letters are represented by larger
integers than the upper case letters.
'''
print(message)
# Load the string variable
stringOfLetters = string.ascii_letters
for myCharacter in stringOfLetters:
print(f"{myCharacter:2s}{ord(myCharacter):3d}")

View file

@ -0,0 +1,15 @@
import string
message = '''
This program prints the Ascii codes for all the letters
in a text string entered by the user.
'''
print(message)
stringOfLetters = input("Enter a name or phrase: ")
# Note: The ord() function returns the integer code for a character.
for myCharacter in stringOfLetters:
print(f"{myCharacter:2s}{ord(myCharacter):3d}")

View 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)

View file

@ -0,0 +1,21 @@
# Example from https://www.geeksforgeeks.org/python-program-to-print-emojis/
print("grinning face ",end="")
print("\U0001f600")
print("grinning squinting face ",end="")
print("\U0001F606")
print("rolling on the floor laughing ",end="")
print("\U0001F923")
print("grinning face ",end="")
print("\N{grinning face}")
print("slightly smiling face ",end="")
print("\N{slightly smiling face}")
print("winking face ",end="")
print("\N{winking face}")

View file

@ -0,0 +1,14 @@
message = '''
This program prints a list of emojis by character code.
This just shows the wide range of emoji's you can
use in your programs.
'''
for i in range(127744,128360):
print(chr(i),end=" ")
print("Next Set")
for i in range(128507,128709):
print(chr(i),end=" ")