HelloWorld - Python

From TRCCompSci - AQA Computer Science
Revision as of 01:36, 10 November 2020 by C3ypt1c (talk | contribs) (Print Command Options: Removed rounded " and changed python to python3 (as all things should be))
Jump to: navigation, search

Writing to the Screen

The first command you will need to learn for Python is the 'print()' command. This will do exactly as you would expect, it prints text to the screen:

print("anything as long as it is between the quotes")

Now to write helloworld to the screen we will need to use:

print("helloworld")

Remember Python is case sensitive so it is important to be precise with your coding

Try this and run your program.

Print Command Options

To display a string without going to a new line:

print ("Hello World" , end="")

To display the contents of a variable without going to a new line:

print (number1, end="")

To display a string and then move the output stream to a new line:

print ("Hello World")

To display the output of a variable and then move the output stream to a new line:

print (number1)

To move the output stream to a new line:

print ()

Now Try

1 Create a sqaure of 5x5, you can do this by writing 5 characters in one line and then copy this line 5 times.

2 Create a triangle, it should be 5 lines high, the point should have a single character.

3 Create a program to write out the chorus of you favourite song.