Programming 1
About this course
Prof (FH). Dr. Dhungana • Dr. Lehner
WS2024/25 • Krems
Image from: https://www.alliancembs.manchester.ac.uk/blogs/what-programming-languages-are-useful-for-data-analysis/
What people think
when I tell them, I teach python programming!
About this course
“Introduction to Python” (IL = Theory + Exercise)
Goal: Develop a good sense of computational thinking and coding in Python
Thousands of online books, tutorials, videos, courses
https://www.google.com/search?q=learn+python
Book: Fundamentals of Python Programming
https://python.cs.southern.edu/pythonbook/pythonbook.pdf
Official Python Tutorial
https://docs.python.org/3/tutorial/index.html
https://www.amazon.com/Learn-Python-
Hard-Way-Introduction/dp/0321884914
3
Course Format
Learning by Doing
Course material: Slides, some code examples will be
provided. Take notes during class, not everything is on
the slides.
Use additional online resources, quizzes, tutorials,
exercises, webcasts etc.
Course materials and exercises are all available
through MS Teams
Always DO IT YOURSELF
Never copy from the internet
or from your colleagues,
or any other form of external Intelligence
(zero benefit, zero tolerance)
https://www.iseazy.com/blog/learning-by-doing/
4
Assessments and Grading
Exercises are not optional
Mandatory
0% E-learning Units in Datacamp
50% Classroom Assessment on 27.11.2024 practical exercises
(hammer exercises)
50% Final Exam on 22.01.2025
You may be asked to present your solution to the
hammer exercises in the classroom.
5
6
Use your IMC email address and the following link to join!
https://www.datacamp.com/groups/shared_links/73e97f4482ef6bc30fe1ae370db691b057f2e4cf86f6c3000b905a7e527d9a35
Coding
Programming
Software Engineering
Informatics
Digitalisation
What is Programming?
7
What is programming?
8
https://en.wikiversity.org/wiki/Introduction_to_Programming/About_Programming 8
How to eat a Kiwi?
Warm up exercise
Give detailed instructions about how to eat a kiwi?
Make your instructions as detailed as possible, so that even
someone who has never eaten a kiwi before can understand them
9
How to eat a Jackfruit?
Warm up exercise
Give detailed instructions about how to eat a Jackfruit?
Make your instructions as detailed as possible, so that even
someone who has never eaten a kiwi before can understand them
10
What is a programming language?
A programming language is somewhat like a natural
language, but with a very limited set of statements and
strict syntax rules.
Has statements to implement sequential, conditional
and iterative processing - algorithms
Examples: FORTRAN, COBOL, Lisp, Basic, Pascal, C, C++,
Java, C#, Python, …
https://en.wikipedia.org/wiki/Lists_of_programming_languages
11
11
Types of Programming Languages
Domain-Specific General Assembly Machine
https://www.youtube.com/watch?v=RPQD7-AOjMI
12
Machine Language
The representation of a computer program which is actually read and understood by the computer.
• A program in machine code consists of a sequence of machine instructions.
Instructions:
• Machine instructions are in binary code
• Instructions specify operations and memory cells involved in the operation
Operation Address
0010 0000 0000 0100
0100 0000 0000 0101
0011 0000 0000 0110
https://homepage.divms.uiowa.edu/~jones/cards/codes.html
13
13
Assembly Language
• A symbolic representation of the machine language of a specific processor.
• Is converted to machine code by an assembler.
• Usually, each line of assembly code produces one machine instruction (One-to-one
correspondence).
• Programming in assembly language is slow and error-prone but is more efficient in
terms of hardware performance.
• Mnemonic representation of the instructions and data
Example:
Load Price
Add Tax Cost = Price + Tax
Store Cost
Assemble revision 001 of AGC program LMY99 by NASA 2021112-61
# 16:27 JULY 14, 1969
14
https://github.com/chrislgarry/Apollo-11/tree/master/Luminary099 14
High Level Language
• A programming language which use statements consisting of English-like keywords such as "FOR", "PRINT" or “IF“, ... etc.
• Each statement corresponds to several machine language instructions (one-to-many correspondence).
• Much easier to program than in assembly language.
• Data are referenced using descriptive names
• Operations can be described using familiar symbols
Example:
Cost = Price + Tax
15
Domain-specific Language
• Domain Specific Languages are languages created to support a particular set of tasks, as they
are performed in a specific domain.
• Languages are tools to solve problems and Domain Specific Languages are specific tools,
good to solve a limited set of problems.
DOT
https://tomassetti.me/domain-specific-languages/
16
Compilers and Programs
Compiler
• A program that converts another program from some source language (or high-
level programming language / HLL) to machine language (object code).
• Some compilers output assembly language which is then converted to machine
language by a separate assembler.
• Is distinguished from an assembler by the fact that each input statement, in
general, correspond to more than one machine instruction.
Algorithm
Program
Executable
17
Interpreters
• An alternative to a compiler is a program called an
interpreter.
• Rather than convert our program to the language of
the computer, the interpreter takes our program
one statement at a time and executes a
corresponding set of machine instructions.
Edit
Syntax error
Interpreter
Input Output
Runtime error
18
Program Errors
Syntax errors:
• Errors in grammar of the language
Runtime errors:
• When there are no syntax errors, but the
program can’t complete execution
• Divide by zero
• Invalid input data Edit
Logical errors:
• The program completes execution, but
Syntax error
Compiler
delivers incorrect results
• Incorrect usage of parentheses
Run
Input Output
Runtime error
19
Popularity of Programing Languages
https://pypl.github.io/PYPL.html
20
Getting Started With Python
Python is a real-world, production language
that is freely available for most computers.
http:www.python.org
Goals:
• An easy and intuitive language just as
powerful as major competitors
• Open source, so anyone can contribute
to its development
• Code that is as understandable as plain
English
• Suitability for everyday tasks, allowing for
short development times
21
Setting up Python Programming Environment
There are many ways to install Python on your laptop/PC/etc.
https://www.python.org/downloads/
https://www.enthought.com/product/enthought-python-distribution/
https://python-xy.github.io/
Most popular option: Anaconda
https://www.anaconda.com/download/
Anaconda is a packaged set of programs including the Python language, a huge number of libraries,
and several tools.
These include the Spyder development environment and Jupyter notebooks.
22
Experienced Programmers?
Here is a programming task to test your skills. Try solving it in 10 minutes.
This is a sample final exam question. Optional for now, must be solved in January 2025.
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a
different order.
Write a Python function called permutedX, which takes two numbers p and q as input and returns the
smallest positive integer x between p and q, such that 2x, 3x, 4x, 5x, contain the same digits.
Based on your implementation, what is the output of the function for the following input parameters? For
example: permutedX(1,150000) should return 142857.
permutedX (1, 1000000) 142857
permutedX (142858, 10000000) 1428570
permutedX (1428571, 100000000) 1429857 Test cases for evaluation
permutedX (1429858, 100000000) 14285700
permutedX (14285701, 100000000) 14298570
23
Experienced Programmers?
Here is a programming task to test your skills. Try solving it in 15 minutes.
This is a sample final exam question. Optional for now, must be solved in January 2025.
The palindromic number 434 is interesting because it can be written as the sum of consecutive squares:
112 + 122 + 132 = 121 + 144 + 169 = 434
There are exactly eleven palindromes below one-thousand that can be written as consecutive square
sums, and the sum of these palindromes is 4164. Note that 1 = 02 + 12 has not been included as this
problem is concerned with the squares of positive integers.
Write a Python function called check which takes an input parameter n and returns the total count of
numbers below n that are both palindromic and can be written as the sum of consecutive squares.
Based on your implementation, what is the output of the function for the following input parameters?
check(1000) 11
For example: check(7890) 17
check(123456) 31 Test cases for evaluation
check(45623) 24
check(98765) 29
24