Python 1.3

Data Types

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • To have Python installed or use CodeGrade’s editor.
  • To have learned about print statements with strings.

Learning goals:

  • Explore Python’s data types.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

You have already come across values in Python, these are things like `“Hello World!”` or the number `15`. All values in Python are objects that belong to a specific data type. Mastering these data types (which are universally used in many programming languages) is key to mastering a programming language.

Python has many data types and data structures built in. In this assignment you will explore the four important date types: `string`, `integer`, `float` and `bool`.

  • The famous `“Hello World!”` is a (so called because it contains a string of letters). Strings are always enclosed in single or double quotation marks.
  • The number `15` is an integer or `int`. This data type holds any whole number, positive or negative, of unlimited length.
  • The other common number data type is the `float`, for floating point numbers. This is any real number, positive or negative, containing one or more decimals. The number pi (`3.14`) would be a floating point number.
  • Finally, `bool` represents a boolean value. This is either `True` or `False`, written in Python with the first letter capitalized.

For this assignment, create a Python script called `types.py`. In this script, you must use Python’s built in `type()` function in a print statement to explore the type of the values you put in. Try these out yourself:

  • Does `print(type(“100”))` return an `int` or a `str`(ing)?
  • Does `print(type(1.6e-5))` return a `float`? Or is scientific notation not supported?
  • What does `print(type(True))` return? And what does `print(type(“True”))` return?

Example usage:

-!- CODE language-bash -!-$ python3 types.py
<class 'str'>
<class 'float'>
<class 'bool'>
<class 'str'>

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.

With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.