Files
2025-08-04 12:58:29 -04:00

36 lines
660 B
Python

# Given the initial statements
# s1 = "spam"
# s2 = "ni!"
# Show the result of evaluating each of the following string expressions.
# a) "The knights who say, " + s2
# b) 3 * s1 +2 * s2
# c) a1[1]
# d) s1[1:3]
# e) s1[2] + s2[:2]
# f) s1 + s2[-1]
# g) s1.upper()
# h) s1.upper().1just(4) * 3
## Initialization
s1 = "spam"
s2 = "ni!"
StringValues = {
"a": "The knights who say, " + s2,
"b": 3 * s1 + 2 * s2,
"c": s1[1],
"d": s1[1:3],
"e": s1[2] + s2[:2],
"f": s1 + s2[-1],
"g": s1.upper(),
"h": s1.upper().ljust(4) * 3,
}
def main():
for key, value in StringValues.items():
print(f"{key}) {value}")
main()