Szkoła Podstawowa nr 1 w Jarosławiu – Informatyka

🐍 Wprowadzenie do programowania w Pythonie

Dział 2.1 – Klasa 8 Szkoły Podstawowej. Dowiedz się, czym jest algorytm i program, poznaj środowisko IDLE i napisz swój pierwszy program w języku Python.

AlgorytmSchemat blokowyPython IDLEprint()Tryb interaktywnyTryb skryptowy

🐍 Introduction to Python Programming

Unit 2.1 – Grade 8. Learn what an algorithm and a program are, discover the IDLE environment and write your first Python program.

AlgorithmFlowchartPython IDLEprint()Interactive modeScript mode

📋 Spis treści

  1. Sposoby przedstawiania algorytmów
  2. Na czym polega programowanie
  3. Środowisko programistyczne IDLE
  4. Tryb interaktywny i skryptowy
  5. Funkcja print()
  6. Błędy w programie
  7. Ćwiczenia interaktywne
  8. Quiz – sprawdź wiedzę

📋 Table of Contents

  1. Ways to represent algorithms
  2. What is programming?
  3. IDLE programming environment
  4. Interactive and script mode
  5. The print() function
  6. Errors in a program
  7. Interactive exercises
  8. Quiz – test your knowledge

1 Sposoby przedstawiania algorytmów Ways to represent algorithms

Algorytm to uporządkowany i uściślony sposób rozwiązania danego problemu, zawierający szczegółowy opis wykonywanych czynności w skończonej liczbie kroków. An algorithm is an ordered and precise method of solving a given problem, containing a detailed description of the steps to be carried out in a finite number of steps.

Aby rozwiązać dowolny problem, nie tylko z informatyki, należy rozpocząć od poprawnego sformułowania problemu oraz ustalenia danych i warunków. Należy też określić cel, czyli wyniki, które chcemy otrzymać, a także warunki, jakie powinny one spełniać. To solve any problem – not only in computer science – you should start by correctly formulating the problem and establishing the data and conditions. You also need to define the goal, i.e. the results you want to obtain, and the conditions they should meet.

Etapy rozwiązywania problemuProblem-solving stages

  1. Sformułowanie zadania.Formulating the task.
  2. Określenie danych wejściowych.Identifying the input data.
  3. Ustalenie celu, czyli wyniku.Establishing the goal (output).
  4. Określenie metody rozwiązania – wybór algorytmu.Choosing the method of solution – selecting an algorithm.
  5. Przedstawienie algorytmu w wybranej postaci.Representing the algorithm in a chosen form.
  6. Analiza poprawności rozwiązania.Analysing the correctness of the solution.
  7. Testowanie rozwiązania dla różnych danych.Testing the solution for different data.

Sposoby zapisu algorytmuWays to write an algorithm

Specyfikacja zadaniaTask specification

Przykład: Oblicz pole trójkąta o podstawie a i wysokości h.
Dane: a, h (liczby rzeczywiste dodatnie).
Wynik: wartość pola p.
Związek: p = a · h / 2
Example: Calculate the area of a triangle with base a and height h.
Input: a, h (positive real numbers).
Output: area value p.
Relationship: p = a · h / 2

Schemat blokowy – podstawowe figuryFlowchart – basic shapes

FiguraShape NazwaName OpisDescription
START Początek algorytmuAlgorithm start Owalna figura z napisem „Start". Jedno wychodzące połączenie.Oval shape labelled "Start". One outgoing connection.
Input (b) Wprowadzanie danychInput block Służy do wprowadzania danych.Used to receive input data.
s = a + b Wykonywanie działańProcess block Blok z obliczeniami.Contains calculations or operations.
Output (s) Wyprowadzanie wynikówOutput block Służy do wyprowadzania wyników.Used to display or output results.
KONIEC / END Zakończenie algorytmuAlgorithm end Owalna figura z napisem „Koniec".Oval shape labelled "End".

Przykładowy schemat blokowy – pole trójkątaExample flowchart – triangle area

START
Wprowadź (a, h)Input (a, h)
p = a · h / 2
Wyprowadź (p)Output (p)
KONIECEND
Ważne: W algorytmach informatycznych dane wejściowe powinny być precyzyjnie określone, a wszystkie operacje – dokładnie opisane. Dla tych samych danych powinniśmy zawsze otrzymać te same wyniki. Important: In computer algorithms, input data must be precisely defined and all operations clearly described. For the same input data, we should always get the same results.

2 Na czym polega programowanie What is programming?

Aby przedstawić algorytm w postaci programu komputerowego, trzeba zapisać go jako ciąg instrukcji języka programowania. Powstaje wówczas tzw. program (kod) źródłowy. To represent an algorithm as a computer program, it must be written as a sequence of programming language instructions. The result is called source code.

Podział języków programowaniaTypes of programming languages

🔼 Języki wysokiego poziomuHigh-level languages

Np. Python, C++, Java. Zrozumiałe dla człowieka, wymagają tłumaczenia na język komputera.E.g. Python, C++, Java. Human-readable, but require translation for the computer.

🔽 Języki niskiego poziomuLow-level languages

Np. Assembler. Bliskie językowi wewnętrznemu komputera.E.g. Assembly. Close to the computer's internal machine language.

Translacja – jak komputer rozumie program?Translation – how does the computer understand a program?

⚙️ KompilacjaCompilation

Tłumaczenie całego programu za jednym razem. Języki: C++, Pascal.Translating the entire program at once. Languages: C++, Pascal.

▶️ InterpretacjaInterpretation

Tłumaczenie i wykonywanie instrukcja po instrukcji. Języki: Python, Scratch.Translating and executing instruction by instruction. Languages: Python, Scratch.

Python jest językiem interpretowanym. Interpreter Pythona czyta kod linia po linii i wykonuje instrukcje. Jeśli napotka błąd, zatrzymuje się i wyświetla komunikat. Python is an interpreted language. The Python interpreter reads the code line by line and executes instructions. If it encounters an error, it stops and displays an error message.

3 Środowisko programistyczne IDLE IDLE programming environment

Aby tworzyć programy w Pythonie, instalujemy darmową aplikację Python, w której skład wchodzi zintegrowane środowisko programistyczne IDLE. To write Python programs, we install the free Python application, which includes the integrated development environment IDLE.

IDLE zawiera narzędzia ułatwiające pisanie programów:IDLE contains tools that make programming easier:

Znak zachęty >>> w oknie powłoki Pythona informuje, że interpreter jest gotowy na przyjęcie polecenia. The prompt >>> in the Python Shell window means the interpreter is ready to accept a command.

4 Tryb interaktywny i tryb skryptowy Interactive mode and script mode

Tryb interaktywnyInteractive mode

Wpisujemy jedno polecenie i zatwierdzamy klawiszem Enter. Interpreter natychmiast je wykonuje. Służy do szybkiego sprawdzania działania pojedynczych instrukcji. We type one command and confirm with Enter. The interpreter executes it immediately. Used to quickly test individual instructions.

Tryb skryptowy – piszemy programScript mode – writing a program

Piszemy wiele poleceń (skrypt), zapisujemy do pliku i uruchamiamy.We write many commands (a script), save them to a file, and run it.

Etapy tworzenia programu w PythonieSteps to create a Python program

  1. W oknie powłoki z menu File wybieramy New File.In the Shell window, choose File → New File.
  2. W edytorze piszemy kod źródłowy programu.In the editor, type the source code of the program.
  3. Zapisujemy plik: File → Save As.Save the file: File → Save As.
  4. Uruchamiamy program: Run → Run Module lub klawisz F5.Run the program: Run → Run Module or press F5.
Uwaga: Pliki programów w języku Python mają rozszerzenie .py. Note: Python program files have the .py extension.

5 Funkcja print() – wyświetlanie komunikatów The print() function – displaying output

Aby wyświetlać na ekranie komunikaty i wyniki, stosujemy funkcję print(). Argumentami mogą być teksty, wyrażenia arytmetyczne lub zmienne oddzielone przecinkami. To display messages and results on screen, we use the print() function. Arguments can be text, arithmetic expressions, or variables separated by commas.

Przykłady użycia funkcji print()Examples of using print()

InstrukcjaInstruction Wynik na ekranieOutput on screen
print("Informatyka")Informatyka
print(23 + 17)40
print(wzrost)wartość zmiennej wzrostvalue of variable wzrost
print("Sum:", 345 + 36)Sum: 381
Ważne: Tekst umieszczamy w apostrofach (pojedynczych lub podwójnych). Po wyświetleniu komunikatu następuje przejście do nowego wiersza. Important: Text is placed inside quotes (single or double). After displaying a message, the cursor moves to a new line.

Pierwszy programFirst program

print("I am in computer science class.")
print("I am working in script mode.")
print("Zofia")
Kolory w IDLE: Nazwy funkcji – fioletowy. Napisy w nawiasach – zielony. Wyniki w powłoce – niebieski. Komunikaty błędów – czerwony. IDLE colours: Function names – purple. Strings in brackets – green. Output in shell – blue. Error messages – red.

6 Błędy w programie – jak je rozumieć? Errors in a program – how to understand them?

Interpreter wykonuje kod linia po linii. Gdy napotka błąd, wyświetla komunikat i zatrzymuje się – kolejne instrukcje nie zostaną wykonane. The interpreter executes code line by line. When it finds an error, it displays a message and stops – the remaining instructions are not executed.

Przykład błędu – literówkaExample error – typo

print("I am in computer science class.")
prnt("I am working in script mode.")   # error!
print("Zofia")
NameError: name 'prnt' is not defined

Jak naprawić błąd?How to fix an error?

  1. Odczytaj komunikat – wskazuje rodzaj błędu i numer linii.Read the message – it shows the type of error and the line number.
  2. Popraw błąd w edytorze.Fix the error in the editor.
  3. Zapisz plik ponownie.Save the file again.
  4. Uruchom program jeszcze raz.Run the program again.

Typowe komunikaty o błędachCommon error messages

KomunikatMessage PrzyczynaCause Jak naprawić?How to fix?
NameError: name '...' is not defined Literówka w nazwie funkcji/zmiennejTypo in function/variable name Sprawdź pisownięCheck the spelling
SyntaxError: Missing parentheses Brak nawiasów przy printMissing parentheses in print print("text")
IndentationError Błędne wcięcie koduWrong code indentation Używaj 4 spacjiUse 4 spaces

7 Ćwiczenia interaktywne Interactive exercises

Odpowiedz na pytania. Do statystyk liczy się wyłącznie pierwsza odpowiedź. Answer the questions. Only the first answer counts towards your score.

🧩 Blok A – Algorytm i schemat blokowyBlock A – Algorithm and flowchart

🧩 Blok B – Programowanie i IDLEBlock B – Programming and IDLE

🧩 Blok C – Funkcja print() i błędyBlock C – The print() function and errors

8 Quiz – sprawdź swoją wiedzę (20 pytań) Quiz – test your knowledge (20 questions)

Pytania z całego działu. Questions covering the entire unit.

✅ Po tej lekcji powinieneś/powinnaś:

✅ After this lesson you should be able to: