Python 1.2

Print Variations

  • 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.

Learning goals:

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

Task:

Now that you have created your first Hello World Python program using the `print` statement, we can further explore the it. In short: it prints whatever argument(s) you pass to it onto the screen.

The print function takes one or more arguments. `print(“Hello World!”)` gives it one argument, namely the string “Hello World!”. It is also possible to have multiple arguments, which will be printed on the screen after each other with a space in between them, e.g.: `print(“Hello”, “World!”)`.

Python’s `print` function can also take in non-string arguments (a string is a data type in Python, it is a value that is surrounded by either single or double quotation marks, you will learn more about data types later). For instance, it can take in an integer or even a calculation. Any object you give to it will be converted to a string before being written to the screen.

For this assignment, create a Python script called `prints.py`. In this script, play around with the print statement in Python. Your script should have 3 `print` statements that altogether meet the following criteria:

  • One `print` function call should have at least two arguments.
  • One `print` function call should have the integer 15 as an argument.
  • One `print` function call should have a sum of two integers as the argument, of which the result can be anything. E.g. you can use `print(20 + 3)`.

Example usage:

-!- CODE language-bash -!-$ python3 prints.py
Hello World!
15
23

$ python3 prints.py
Two words
15
700

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.