Instructions
Use a for loop to write a function has_digit
that consumes a nonempty string and determines whether or not there is at least one digit in the string, producing True
if so and False
otherwise.
Note:
Hints:
- Use
isdigit
to check if a character is a digit.
Use a for loop to write a function my_power
that consumes two inputs base
and exponent
, where base
is a non-negative integer or floating point number and exponent
is a non-negative integer. Your function should produce base
to the exponent
power. The computation should be made using repeated multiplication.
Note:
Hints:
- The number of iterations should be equal to
exponent
.
Use a for loop to write a function no_nums
that consumes a string and produces a string which has the same characters as the input but with all digits removed.
Note:
Hints:
- Use
isdigit
to check if a character is a digit.
Use a for loop to write a function swap_case
that consumes a string and produces a string which has the same characters as the input but with any lower-case letter replaced by the corresponding upper-case letter and any upper-case letter replaced by the corresponding lower-case letter.
Note:
Hints:
- Use
lower
andupper
to find corresponding lower-case and upper-case letters.
A Canadian postal code is of the form "A9A 9A9"
, where 9
represents a digit and A
represents an upper-case letter.
Fill in the helper functions and the main function, using for loops in the helper functions.
Do not allow lower-case letters.
Note:
Hints:
- Use
isspace
to determine if a character is a space.