Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "AmigaOS Manual: Python Getting Started"
(Added an introduction) |
(Added example Age.py) |
||
Line 23: | Line 23: | ||
Amiga. The Computer for the Creative Mind. |
Amiga. The Computer for the Creative Mind. |
||
+ | |||
+ | == Age.py == |
||
+ | |||
+ | This program displays a prompt for input and then reads the entered information. |
||
+ | |||
+ | === Program 2. Age.py === |
||
+ | |||
+ | <syntaxhighlight lang="python"> |
||
+ | # Calculate age in days |
||
+ | age = input( 'Please enter your age: ' ) |
||
+ | print( 'You are about ' + str( age * 365 ) + ' days old.' ) |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | Save this program as '''PYTHON:Scripts/Age.py''' and run it with the command: |
||
+ | |||
+ | Python PYTHON:Scripts/Age.py |
Revision as of 23:10, 8 January 2019
Contents
Running Python programs
Using Python interactively
How to write Python programs
Amiga.py
This program shows how to use print() to display text on the screen. Print() is a function which can print the given object to the screen or to a file. In the following example text "Amiga. The Computer For the Creative Mind." will be printed on the screen. The text in the source code is surrounded by single quotes (') but you can also use double quotes (").
Program 1. Amiga.py
# A simple program print( 'Amiga. The Computer For the Creative Mind.' )
Enter the above program using your favourite text editor, and save it as PYTHON:Scripts/Amiga.py. To run the program, open a Shell window and type:
Python PYTHON:Scripts/Amiga.py
You should see the following text in your Shell window:
Amiga. The Computer for the Creative Mind.
Age.py
This program displays a prompt for input and then reads the entered information.
Program 2. Age.py
# Calculate age in days age = input( 'Please enter your age: ' ) print( 'You are about ' + str( age * 365 ) + ' days old.' )
Save this program as PYTHON:Scripts/Age.py and run it with the command:
Python PYTHON:Scripts/Age.py