Difference between revisions of "HelloWorld - Python"
(Created page with "=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:...") |
m (→Writing to the Screen: added python link and formatting) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
=Writing to the Screen= | =Writing to the Screen= | ||
− | The first command you will need to learn for Python is the | + | The first command you will need to learn for Python is the [https://docs.python.org/3/library/functions.html#print print] command. This will do exactly as you would expect, it prints text to the screen: |
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
Line 6: | Line 6: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Now to write | + | Now to write <code>helloworld</code> to the screen we will need to use: |
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
− | print(" | + | print("helloworld") |
</syntaxhighlight> | </syntaxhighlight> | ||
'''Remember Python is case sensitive so it is important to be precise with your coding''' | '''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: | ||
+ | <syntaxhighlight lang=python3> | ||
+ | print ("Hello World" , end="") | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | To display the contents of a variable without going to a new line: | ||
+ | <syntaxhighlight lang=python3> | ||
+ | print (number1, end="") | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | To display a string and then move the output stream to a new line: | ||
+ | <syntaxhighlight lang=python3> | ||
+ | print ("Hello World") | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | To display the output of a variable and then move the output stream to a new line: | ||
+ | <syntaxhighlight lang=python3> | ||
+ | print (number1) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | To move the output stream to a new line: | ||
+ | <syntaxhighlight lang=python3> | ||
+ | print () | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | =Now Try= | ||
+ | # Create a square of 5x5, you can do this by writing 5 characters in one line and then copy this line 5 times. | ||
+ | # Create a triangle, it should be 5 lines high, the point should have a single character. | ||
+ | # Create a program to write out the chorus of your favourite song. |
Latest revision as of 00:40, 10 November 2020
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
- Create a square of 5x5, you can do this by writing 5 characters in one line and then copy this line 5 times.
- Create a triangle, it should be 5 lines high, the point should have a single character.
- Create a program to write out the chorus of your favourite song.