String Methods
Remember: String formatting can be very useful when creating strings for printing to the console
Step 1
Using the documentation on this page write a script, that takes user input (see exercise 2). And checks whether it is (either)1:
- uppercase
- numeric
- contains the substring
":-)"
2 or - none of the above
report which of these it was. If multiple branches are true, you need only report one.
Step 2
Expand the ‘uppercase’ branch, to not only report that it was uppercase, but also print a lowercase version. 3
Step 3
Expand the ‘numeric’ branch to request a second number from the user and then reporting the sum of the two numbers. 4
Step 4
Expand the ‘none of the above’ branch to split the string at every letter ‘a’ 5 and join these strings together into a new string, inserting semicolons between them. 6
'aglloatyat' -> ['', 'gllo', 'ty', 't'] -> ';gllo;ty;t'
-
python does not have a case statement ↩
-
The using
in
checks for subelements and substrings as well. ↩ -
Typecasting is done by calling the constructor of the target type on the source value* ↩
-
Strings can be split with the
split(separator)
method. This method also accepts a second parameter (int) how often it should split the string at maximum. ↩ -
Strings are joined with the
separator_string.join(['list', 'of', 'strings'])
method. ↩