Text input and output


To output text to the screen you will need one line of code:

print("Hello World")

To write multiple lines, add the ‘\n’ character:

print("Hello World\nThis is a message")

To print variables:

x = 3

To print multiple variables on one line:

x = 2
y = 3
print("x = {}, y = {}".format(x,y))

To get a text value:

name = input("Enter a name: ")

To get a whole number:

x = int(input("What is x? "))

To get a decimal number:

x = float(input("Write a number"))