0% found this document useful (0 votes)
12 views36 pages

Introduction_IT

The document outlines a course on Information Technology, taught by Anni Halkola, focusing on programming basics using Python and concepts of artificial intelligence. It includes course goals, contents, grading criteria, and methods of instruction, such as lectures, exercises, and projects. Additionally, it introduces programming languages, algorithms, flowcharts, and provides examples of Python programming techniques.

Uploaded by

sakil16180ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views36 pages

Introduction_IT

The document outlines a course on Information Technology, taught by Anni Halkola, focusing on programming basics using Python and concepts of artificial intelligence. It includes course goals, contents, grading criteria, and methods of instruction, such as lectures, exercises, and projects. Additionally, it introduces programming languages, algorithms, flowcharts, and provides examples of Python programming techniques.

Uploaded by

sakil16180ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

•Information technology

ET00BN16-3001

•Introduction etc.
About the course

• Teacher: Anni Halkola


[email protected]
•+358504766312
• Disclaimer: I don’t live in Vaasa and I take a train in the morning. Hopefully, VR won't fail me, but so
that you know, there is a possibility of me being late.

5.9.2024 Information Technology 2


About the course

Goals:
• The student knows basics of programming and knows how to write short programs in
some programming language (in this course, we use Python).
• The student knows the consept of artificial intelligence and can use some online tools.

Contents:
• Basic elements of programming: variables, expressions, conditional statement (if
statement), loops (for, while), lists and functions
• Artificial intelligence: machine vision, voice recognition, mobility detection

5.9.2024 Information Technology 3


About the course

• The course consists of


•Lecturing and examples
•Exercises
• Coding etc. exercises that are done during the lectures
• I help and the answers are either checked during that lecture or the next one (depending on the
time it takes)
•Homework
• Submitted in Moodle
• The answers are checked during lecture time after the deadline. I’ll select someone’s answer
and we go through the result (and fix if needed, errors are also needed for learning).
•Artificial intelligence project
• Later in the autumn

5.9.2024 Information Technology 4


About the course

• The grade
•Exam (during the last lecture)
•The homework submitted in Moodle
•The artificial intelligence project

• I’ll mark the attendance.


•In close cases when the grade almost rounds up (e.g. 3,48), active attendance helps.

•Today password: monkey

5.9.2024 Information Technology 5


About the course

• Moodle:
•ET00BN16-3001 Information Technology

•Materials and assignments (homework)

•I’ll also add solutions to the excersises after those have been checked during the
lectures.

5.9.2024 Information Technology 6


Introduction

• Has someone done programming before?

• What is programming?
•Giving instructions, what the computer should do.
•The set of instructions given to a computer to perform a specific task is called a
program

5.9.2024 Information Technology 7


Introduction – Programming languages

• Programming languages are used for programming

• Each programming language has it’s own syntax


•The command words
• E.g. Python has print(”Important stuff”) and Java has System.out.println(”Important stuff”);
•How the commands are arranged
• For example, in some languages the indents are important

• Programming languages can be grouped in various ways: by purpose, by


programming paradigm, by whether they use a compiler or an interpreter, etc.

5.9.2024 Information Technology 8


Introduction – Programming languages

• Grouping by purpose:
•General purpose can be used to write large and versatile software applications for
different fields
• E.g. customer registry maintenance, card and board games, or robot control
• Suitable for both web server applications (e.g., online stores) and desktop applications
• E.g. Java, C#, Visual Basic
•Some programming languages are designed solely for writing web applications
• E.g. PHP
•Others are suitable for system-level programming
• E.g. C
•Some are used for scripting on web pages
• E.g. JavaScript

5.9.2024 Information Technology 9


Introduction – Programming languages

• Grouping by the approach to solving programming tasks (programming


paradigm):
•E.g. procedural languages and object-oriented languages.
•In procedural languages, tasks are approached through functions, determining what
needs to be done.
• The program is divided into functions, which are called to complete the task
• E.g. C

•In object-oriented languages, tasks are approached through objects


• An object has data and can handle this data
• The program code is divided into classes that describe the features of the objects
• The execution of the program consists of interactions between objects

• Many programming languages support both (e.g. Python)


5.9.2024 Information Technology 10
Introduction – Programming languages

• Programming languages can also be categorized as either compiled or


interpreted:
•Once a program is written, it does not work as such but must be translated into
machine language that the computer's processor can understand.
•This is done by the compiler or interpreter of the specific language.
•A compiler processes the entire source code and converts it into machine code.
• The program then has two forms: source code (written by the programmer) and compiled code.
• The computer can run the compiled program.

•An interpreter, on the other hand, processes the source code line by line, translating
each line into machine code, which the computer executes immediately after
translation.
• Python is an interpreted language.

5.9.2024 Information Technology 11


Introduction – Algorithm

• Programming requires logical thinking, and tasks are solved using a specific
thought model
•What is the goal, what is the wanted outcome?
•What needs to be done first?
•What is done after that?
•Are there any conditions that affect the actions. Etc.

• Typically, one first outlines how to act to achieve the desired outcome, forming
an algorithm, which defines the steps required to solve the task
• An algorithm can be visualized using a flowchart.

5.9.2024 Information Technology 12


Introduction – Flowchart

• Flowchart techniques can describe various processes using simple drawing


symbols.
•They can conceptualize task solutions at a rough level or create highly detailed
operational diagrams.
• The following symbols are used:

Start/end Action Condition

A diamond represents a condition,


An oval represents A rectangle represents
with the testable condition written inside.
the start and end an action, with the action
The action branches depending on
description written inside
whether the condition is true or false
5.9.2024 Information Technology 13
Introduction – Flowchart

• Flowchart symbols are connected by arrows that depict the direction of


progression.
• Other symbols can also be used in flowcharts.
•For example, a parallelogram represents input/output actions
•Input e.g: reading data from the user, a file, a database, etc.
•Output e.g: writing results to the display, a file, a database, etc.

5.9.2024 Information Technology 14


Introduction – Sequential structure Start

• When actions follow one another, it


is called a sequential structure, Ask for a number
which is commonly part of other
structures.
Calculate
the squareroot

Print the squareroot

End
5.9.2024 Information Technology 15
Introduction – Start

Selection structure Ask for a number

FALSE
Number ≥ 0
• When selecting from
alternative actions, it is called TRUE
a selection structure. Calculate
• This requires a condition Print error message
the squareroot

Print the squareroot

5.9.2024 Information Technology


End 16
Start
Introduction –
Repetition structure Ask the file name

• Many tasks involve repeating the same


Open the file
action until a certain condition is met,
known as a repetition structure.
• For example, reading lines from a text
file one by one until all lines are read.
TRUE
Any unread lines?
• Handling a file in programming involves
first opening the file and finally closing it.
The file is read one line at a time, and FALSE Read a line
the file pointer moves to the start of the
next line. Close the file

Print the line


End
5.9.2024 Information Technology 17
Introduction - Python

• This material discusses the Python language, using version 3.


•Versatile programming language
•Can be used for different kinds of programs for different kinds of platforms
•Files end with .py

• Programs can be written using


•Any text editor, such as Notepad++, and run from the command line.
•Alternatively, Python's included IDLE tool can be used.
•Or, an integrated development environment (IDE) designed for Python, which includes
an intelligent editor (e.g., notifies of syntax errors) and an interpreter, can be used.
Examples of such tools include Spyder (https://www.spyder-ide.org/), PyCharm
(https://www.jetbrains.com/pycharm/), and Visual Studio Code
(https://code.visualstudio.com/).

5.9.2024 Information Technology 18


Introduction - Example 1.1

• In this course we use Visual Studio Code.


• Let’s try a simple example.

5.9.2024 Information Technology 19


Introduction - Example 1.1
Running the program

The code is saved in a file


with the name ending in .py
The code in the editor

The terminal shows the


progress during the run

5.9.2024 Tietotekniikka 20
Introduction - Example 1.1

• Let’s try a simple example


• The program asks the user for their name and prints a message.

5.9.2024 Information Technology 21


Introduction - Example 1.1

• Each line of program code is typically written on its own line.


•If you want to write multiple statements on the same line, separate the statements with
a semicolon (;), but it is usually clearer to write each statement on its own line.

• If a statement is too long to fit on one line, you can break the line within
parentheses (), {}, []. If you break the line elsewhere, put a backslash \ at the
end of the line.

5.9.2024 Information Technology 22


Introduction - Example 1.1

• A space at the beginning of a line is a significant character, indicating


indentation.
•Indentation shows the logical grouping of statements (more on this under control
statements).
•In this example, all program statements start right at the beginning of the line.

5.9.2024 Information Technology 23


Introduction - Example 1.1

• Documentation is additional comments and descriptions in the code. The


documentation is to give information on what the code does (or just notes).
• Gives quick information for someone else using your code. Or if you use some old code and
forgot what it was about.
• Is ignored by the interpreter.
• So called Docstring in the beginning of the file.
• Short introduction: what the code does
• Other information
• Comments can be added in the middle as well
• Starting with # (only one line)
• Comments on multiple lines and Docstrings start
and end with three apostrophes ’’’

5.9.2024 Information Technology 24


Introduction - Example 1.1

• name = input(”What is your name?") a variable name is introduced.


•This reserves memory to store data during the program's execution.
•In Python, you do not need to define a variable explicitly (as in many other
programming languages).
• The input function displays a prompt and waits for the user's input.
•When the user types their name and presses Enter, their input is stored in the name
variable.
•The user’s input end with Enter even if they didn’t write anything.
• The print("Hello", name) command outputs a string
•The text "Hello" is followed by the value of the name variable.
•Python automatically adds a space between them.

5.9.2024 Information Technology 25


Introduction - Errors

• Syntax errors must be corrected before the program can be run


•If there is an error in the program code that violates Python's syntax, a syntax error
occurs.
•The program cannot be run until the error is corrected.
•For example, the following error message is generated if the closing quotation mark
for a string is missing.

5.9.2024 Information Technology 26


Start
Introduction - Example 1.2

• The program calculates a circles area Ask for the radius


and prints it.
• The circle’s radius is asked from the
user. Calculate the area
• Let’s think about the flowchart with the given radius
•What are the steps

Print the area

End

5.9.2024 Information Technology 27


Introduction - Example 1.2 Ask for the radius

5.9.2024 Information Technology 28


Introduction - Example 1.2

• Now we have a variable r which will have the user-given value when the
program is run.
• The next step would be
Calculate the area
with the given radius

5.9.2024 Information Technology 29


Calculate the area
Introduction - Example 1.2 with the given radius

• However, first we must do one thing:


• The input function takes the user's input as a string (text), but it must be
converted to a number to be used in calculations: r = float(r) converts the
string to a float

5.9.2024 Information Technology 30


Calculate the area
Introduction - Example 1.2 with the given radius

• Here we use an approximation for π

5.9.2024 Information Technology 31


Introduction - Esimerkki 1.2

• area = 3.1415926 * r ** 2
• Python supports standard arithmetic operators + (addition), - (subtraction), *
(multiplication), / (division).
•The exponentiation operator is **
•Decimal separator is a dot

5.9.2024 Information Technology 32


Print the area
Introduction - Example 1.2

• The last step was to print


the result (i.e. the value of
the variable area.)

5.9.2024 Information Technology 33


Introduction - Example 1.2

• If units are required, provide instructions to the user on what units to use for
the radius and add the unit to the answer

5.9.2024 Information Technology 34


Introduction - Example 1.2

• If a more accurate approximation of π is needed.


•The value of π is available as a constant in Python's math library. The library is
included in the program code with the import math

5.9.2024 Information Technology 35


Introduction - Example 1.3

• If there is extra time


• Write a program that asks the sides of a rectangle from the user. The program
then calculates the area of the rectangle and prints it.
• Then the program calculates the diagonal and prints it as well.

5.9.2024 Information Technology 36

You might also like