# strings - immutable containers of characters accessible by index
course = "Scientific Computing"

# iterating over strings by character
for c in course:
    print("next character: ", c)

# iterating over strings by index
for i in range(len(course)):
    character = course[i]
    print( "next character at index: ", i, " is: ", character )

# functions on strings
l = len(course) # number of characters in the string
newString1 = "CS100 " + course # string concatenation operator (join two strings together)
newString2 = course * 6 # repetition operator (repeat the string)
newString3 = course.replace("Computing", "Programming") # replace all occurrences of "Computing" with "Programming"

# index operator -- return the character at that position
#   positive indices (start from the left)
#   negative indices (start from the right)
firstCharacter = course[0] # return first character
lastCharacter = course[-1] # return character at last index (-1)
someCharacter = course[5]  # return character at index 5

# slice operator
newString3 = course[:6]   # slice operator (start from beginning up to not including index 6)
newString4 = course[10:]  # slice operator (start from index 10 all the way to the end of string)
newString5 = course[6:10] # slice operator (start from index 6 up to not including index 10)

# containment operator
bool1 = "science" in course  # True/False whether the left string is in the right one
bool2 = "science" not in course # True/False whether the left string is NOT in the right one


# capitalization
lowerCase = course.lower() # return a new string with all letters in lowercase
upperCase = course.upper() # return a new string with all letters in uppercase

# finding and counting
occurrences1 = course.count("S") # number of occurrences of "s"
occurrences2 = course.count("Sci") # number of occurrences of "Sci"
idx1 = course.find("Sci") # index where "Sci" first occurs
idx2 = course.find("S") # index where "S" first occurs
idx3 = course.find("!") # returns -1 if item is not found
idx4 = course.index("Sci") #index where "Sci" first occurs
idx5 = course.index("S") # index where "S" first occurs
#idx6 = course.index("!") # throws an error if item is not found (commented out so it doesn't throw an error)


message = input("What string would you like to work with? Type your answer here: ")
print(message)
print("Number of characters:", len(message))


# functions relating numbers to strings/characters
num = ord('b') # ASCII value corresponding to 'b'
ch = chr(97)   # character corresponding to ASCII value 97
newString = str(32) # convert to a string

# justification
print("-"*52) # to observe justification, print the "-" character 52 times
centeredStr = course.center(50) # return a new string of length 50, center justified
leftStr = course.ljust(50)      # return a new string of length 50, left justified
rightStr = course.rjust(50)     # return a new string of length 50, right justified
print( "-" + centeredStr + "-" )
print( "-" + leftStr + "-" )
print( "-" + rightStr + "-" )