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:
-!- CODE language-bash -!-$ python3 prints.py
Hello World!
15
23
$ python3 prints.py
Two words
15
700
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!