Python-kielisen ohjelmoinnin perusteet/Ensimmäinen python-ohjelma

From Wikiversity

Jump to: navigation, search
Stop bad orthography.svg

Please do not edit this page on betawikiversity.

Rename icon.svg Current work has been transferred from betawikiversity to this page on the new fi.Wikiversity.

In the respect about the GFDL and the CC-by-sa licenses, all the text, history and account are be preserved in the transfert.

In case of problem, leave a message here to resolve it quickly

Quill-Nuvola.svg Now, you can continue to work on this page, go to the new wiki with the links above. Maybe you need to create the same account on this new project. So just transform your betawikiversity account to the Unified Login : just click here.

Ohjelman kirjoitus

Python Shellin mukana tulee python-kielen syntaksiväritystä tukeva editori, joka käynnistyy filevalikosta "New Window"-valinnalla.

Esimerkkiohjelma
#!/usr/bin/env python
 
import math
 
print math.sqrt(5)
Esimerkkiohjelman luonti ja suoritus Windows-ympäristössä
  1. Avaa Pythonin mukana tullut IDLE (Python GUI)
  2. Avaa uusi editointi-ikkuna filevalikosta "New Window"-valinnalla sekä kopioi ja liitä yllä oleva teksti editoriin.
  3. Tallenna nimellä ekatesti.py. Muista tiedostopääte .py, koska IDLE ei lisää tiedostomuotoa automaattisesti.
  4. Käynnistä ohjelman suoritus editointi-ikkunan Run-valikon "Run Module"-toiminnolla
  5. Ohjelma tulostaa Shell-ikkunaan: 2.2360679775

[edit] Aiheesta muualla