With Python you control your computer by using Python, a highly intuitive language!
0. Install Python language if you‘re on Windows, if it is not already installed.
1. Open Python (command line). (How? By running python or searching python.exe)
A command prompt appears.
>>> _
Hello World!
Tradition, python2: Enter “print “Hello World!”” and press Enter. You will have on the screen:
>>> print "Hello World!"
Hello World!
>>> _
Python 3: Enter “print (“Hello world.”)” and press Enter/Return. You will have on the screen:
>>> Print ("Hello world.")
Hello world.
>>> _
2. Select “a = 3” and press Enter/Return. In the next prompt type “print a” (or “print (a)” with version 3). You will have on the screen:
>>> a = 3
>>> print a
3
>>> _
3. Enter these commands (be sure to change the print by adding brackets for the code to be compatible with version 3):
>>> a = 0 # Shift+Enter to jump to the next line
>>> while (a<4): # opens a process (1), so ...
... a = a+1 # add an indentation (space) at the beginning to signify membership in the process 1.
... print "week" , a # application to display "week" and a.
...
week 1 # 1st result
week 2
week 3
week 4 # etc., your program runs in a loop until a<4
4. Open a text editor, write ...
a = 0
while (a <20):
a = a + 1
print "week" , a , "2015"
... and save this script as *.py
5. Open your operating system's command line (eg: bash GNU/Linux, Mac OS X Terminal, or cmd for Windows), place the command prompt in the directory of your *.py file, display your *.py file in your command prompt and run it by pressing Enter.
Congratulations, you have written and performed your first script!
Translated from Wikibooks
Discover more from MultiMedia
Subscribe to get the latest posts sent to your email.
Leave a Reply