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.
1Sposoby przedstawiania algorytmówWays 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.
Określenie danych wejściowych.Identifying the input data.
Ustalenie celu, czyli wyniku.Establishing the goal (output).
Określenie metody rozwiązania – wybór algorytmu.Choosing the method of solution – selecting an algorithm.
Przedstawienie algorytmu w wybranej postaci.Representing the algorithm in a chosen form.
Analiza poprawności rozwiązania.Analysing the correctness of the solution.
Testowanie rozwiązania dla różnych danych.Testing the solution for different data.
Sposoby zapisu algorytmuWays to write an algorithm
Opis słowny – ogólny opis wykonywanych operacji.Verbal description – a general description of the operations performed.
Lista kroków – kolejne punkty opisujące dokładne czynności.Step list – numbered points describing each action precisely.
Schemat blokowy – graficzne przedstawienie za pomocą figur geometrycznych.Flowchart – a graphical representation using geometric shapes.
Program – zapis w wybranym języku programowania.Program – written in a chosen programming language.
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 / 2Example: 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
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.
2Na czym polega programowanieWhat 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.
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:
edytor kodu źródłowego – do pisania i zapisywania programów,source code editor – for writing and saving programs,
interpreter – do uruchamiania programów,interpreter – for running programs,
powłokę (shell) – do trybu interaktywnego.shell – for interactive mode.
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.
4Tryb interaktywny i tryb skryptowyInteractive 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
W oknie powłoki z menu File wybieramy New File.In the Shell window, choose File → New File.
W edytorze piszemy kod źródłowy programu.In the editor, type the source code of the program.
Zapisujemy plik: File → Save As.Save the file: File → Save As.
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.
5Funkcja print() – wyświetlanie komunikatówThe 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.
6Błę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?
Odczytaj komunikat – wskazuje rodzaj błędu i numer linii.Read the message – it shows the type of error and the line number.
Popraw błąd w edytorze.Fix the error in the editor.
Zapisz plik ponownie.Save the file again.
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 interaktywneInteractive 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
8Quiz – 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ś:
rozumieć pojęcie algorytmu i znać sposoby jego przedstawiania,