06: Python: Data Types

Debug it:

Convert and use different types of data
Python Data types: Convert and use different types of data

Debugging means finding and fixing errors (bugs) in your code.

Below is some code that has been deliberately broken so that you can find and fix some common mistakes when working with and converting data of different types.

When you’ve fixed it, it will ask you what year you were born and for a year sometime in the future. It will then display how old you’ll be if you’re still around a that date.

e.g.:

Welcome to the 'How old am I going to be in...' calculator
----------------------------------------------------------
What year were you born? e.g. 2007 2001
Please enter a year in the future: e.g. 2070 3000
In the year 3000 you will be 999 years old

Hints: Check the brackets, spelling and quotation marks.

Your code won’t run at all until you’ve fixed all of the errors: You need to fix all the lines of code even before the first line will run.

Remember: input(...) returns a string so if you ask a question where the answer would be a number, you’ll need to surround it with either int(input(...)) or float(input(...)

When you join text together in a print() function, you need to make sure each part is a string so you’ll need to convert any numbers using the str() function.

On the next page you’ll get some ideas for projects that work with data of different types.

Leave a Reply