Chapters
Python114 chapters

Exercises

Casting

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

typed holds the text "25". Print the number 35 by converting before adding.

Python
typed = "25"
# print typed plus 10, as a number
Exercise 2

int("3.5") fails. Convert the text to a whole number anyway, in two steps.

Python
text = "3.5"
# print it as a whole number
Exercise 3

Print ok for text that converts to a number and no for text that does not.

Python
for text in ["12", "twelve"]:
    # print ok or no
    pass