Digital Medicine I Introduction to the Course Hans-Joachim - - PowerPoint PPT Presentation

digital medicine i
SMART_READER_LITE
LIVE PREVIEW

Digital Medicine I Introduction to the Course Hans-Joachim - - PowerPoint PPT Presentation

Departement Informatik Digital Medicine I Introduction to the Course Hans-Joachim Bckenhauer Dennis Komm Autumn 2020 October 1, 2020 Welcome to the Course Material Lecture website https://courses.ite.inf.ethz.ch/digiMed20 Digital


slide-1
SLIDE 1

Departement Informatik

Digital Medicine I

Introduction to the Course

Hans-Joachim Böckenhauer Dennis Komm

Autumn 2020 – October 1, 2020

slide-2
SLIDE 2

Welcome to the Course

slide-3
SLIDE 3

Material

Lecture website

https://courses.ite.inf.ethz.ch/digiMed20

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 1 / 38

slide-4
SLIDE 4

The Team

Lecturers Hans-Joachim Böckenhauer Dennis Komm Assistants Imant Daunhawer Fabian Frei Lea Fritschi Sarah Kamp Safira Piasko

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 2 / 38

slide-5
SLIDE 5

Appointments

Lecture Thursday, 8:15 – 10:00, HG F 3 Exercises Tuesday, 10:15 – 11:45, CHN F 46 Thursday, 10:15 – 12:00, HG F 3 Exam Thursday, 10.12.2020

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 3 / 38

slide-6
SLIDE 6

Goal of Today’s Lecture

General information about the lecture The projects, using [code]expert and PELE Introduction to computers and algorithms The first Python program

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 4 / 38

slide-7
SLIDE 7

Introduction to the Course

Computers and Algorithms

slide-8
SLIDE 8

Computer – Concept

What does a computer have to be able to do to compute? Does it have to be able to multiply? Isn’t it sufficient to be able to add?

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 5 / 38

slide-9
SLIDE 9

Computer – Concept

What does a computer have to be able to do to compute? Does it have to be able to multiply? Isn’t it sufficient to be able to add? Turing Machine [Alan Turing, 1936] Finite number of states Memory consisting of arbitrarily many cells Pointer to current cell Pointer can change cell’s content and move left or right

Alan Turing [Wikimedia] Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 5 / 38

slide-10
SLIDE 10

Computer – Implementation

Analytical Engine – Charles Babbage (1837) Z1 – Konrad Zuse (1938) ENIAC – John von Neumann (1945)

Charles Babbage [Wikimedia] Konrad Zuse [Wikimedia] John von Neumann [Wikimedia] Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 6 / 38

slide-11
SLIDE 11

Algorithm: Central Notion of Computer Science

Algorithm Method for step-by-step solution of a problem

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 7 / 38

slide-12
SLIDE 12

Algorithm: Central Notion of Computer Science

Algorithm Method for step-by-step solution of a problem Execution does not require intellect, only accuracy

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 7 / 38

slide-13
SLIDE 13

Algorithm: Central Notion of Computer Science

Algorithm Method for step-by-step solution of a problem Execution does not require intellect, only accuracy after Muhammad al-Chwarizmi; author of a arabic math book (around 825)

"‘Dixit algorizmi. . . "’ Latin translation [Wikimedia] Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 7 / 38

slide-14
SLIDE 14

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b = 0 if a > b then a = a − b else b = b − a Output: a

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-15
SLIDE 15

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b = 0 if a > b then a = a − b else b = b − a Output: a

a b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-16
SLIDE 16

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b = 0 if a > b then a = a − b else b = b − a Output: a

a b a b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-17
SLIDE 17

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b = 0 if a > b then a = a − b else b = b − a Output: a

a b a b a b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-18
SLIDE 18

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b = 0 if a > b then a = a − b else b = b − a Output: a

a b a b a b a b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-19
SLIDE 19

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’s Elements, 300 BC

Input: integers a > 0, b > 0 Output: gcd of a and b

Input: a and b while b != 0: if a > b: a = a − b else: b = b − a Output: a

a b a b a b a b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 8 / 38

slide-20
SLIDE 20

Introduction to the Course

Goals

slide-21
SLIDE 21
  • 1. Computer Science in the Natural Sciences

problem from praxis solution to problem from practice

?

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 9 / 38

slide-22
SLIDE 22
  • 1. Computer Science in the Natural Sciences

problem from praxis computer science problem solution to comp. science problem solution to problem from practice

ACTGCATGGC A C G C T A A G C A C T G C A T G G C C A A ACGCTAAGCACTGCATGGCCAA

modeling interpretation

?

algorithmics, concepts of programming

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 9 / 38

slide-23
SLIDE 23
  • 1. Computer Science in the Natural Sciences

problem from praxis computer science problem solution to comp. science problem solution to problem from practice

ACTGCATGGC A C G C T A A G C A C T G C A T G G C C A A ACGCTAAGCACTGCATGGCCAA

modeling interpretation

c

  • m

m u n i c a t i

  • n

b e t w e e n p r a c t i c e a n d c

  • m

p . s c i e n c e

?

algorithmics, concepts of programming

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 9 / 38

slide-24
SLIDE 24
  • 1. Computer Science in the Natural Sciences

problem from praxis computer science problem solution to comp. science problem solution to problem from practice

ACTGCATGGC A C G C T A A G C A C T G C A T G G C C A A ACGCTAAGCACTGCATGGCCAA

modeling interpretation

c

  • m

m u n i c a t i

  • n

b e t w e e n p r a c t i c e a n d c

  • m

p . s c i e n c e n e e d s b a s i c k n

  • w

l e d g e

?

algorithmics, concepts of programming

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 9 / 38

slide-25
SLIDE 25
  • 2. Computational Thinking

Systematic solving of given problems This implies creativity, abstraction skills etc. Formulation of solution as algorithm Solution can be “understood” by a computer

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 10 / 38

slide-26
SLIDE 26
  • 2. Computational Thinking

Seymour Papert Erfinder der Programmiersprache Logo Schüler von Jean Piaget Professor am MIT Erste Erwähnung des Begriffs

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 11 / 38

slide-27
SLIDE 27
  • 2. Computational Thinking

Seymour Papert Erfinder der Programmiersprache Logo Schüler von Jean Piaget Professor am MIT Erste Erwähnung des Begriffs

"‘My central focus is not on the machine but on the mind. "’

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 11 / 38

slide-28
SLIDE 28
  • 2. Computational Thinking

Jeannette Wing Professorin an der Columbia University Popularisierung des Begriffs

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 12 / 38

slide-29
SLIDE 29
  • 2. Computational Thinking

Jeannette Wing Professorin an der Columbia University Popularisierung des Begriffs "‘Computational thinking is a way humans solve problems; it is not trying to get humans to think like computers. Computers are dull and boring; humans are clever and imaginative. We humans make computers exciting. "’

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 12 / 38

slide-30
SLIDE 30
  • 3. Algorithms Design Techniques

Most practically relevant problems have easy solutions

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 13 / 38

slide-31
SLIDE 31
  • 3. Algorithms Design Techniques

Most practically relevant problems have easy solutions Easy to implement Are based on trying out possibly many possibilities (“solution candidates”) This means impractically large time to spend

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 13 / 38

slide-32
SLIDE 32
  • 3. Algorithms Design Techniques

Most practically relevant problems have easy solutions Easy to implement Are based on trying out possibly many possibilities (“solution candidates”) This means impractically large time to spend Many problem allow for “faster” solutions

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 13 / 38

slide-33
SLIDE 33
  • 3. Algorithms Design Techniques

Most practically relevant problems have easy solutions Easy to implement Are based on trying out possibly many possibilities (“solution candidates”) This means impractically large time to spend Many problem allow for “faster” solutions Needs a little more skill Different techniques: greedy algorithms, divide and conquer, dynamic programming etc.

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 13 / 38

slide-34
SLIDE 34

Introduction to the Course

Projects

slide-35
SLIDE 35

Projects

During the semester, you work on a few small projects

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 14 / 38

slide-36
SLIDE 36

Projects

During the semester, you work on a few small projects The project tasks will be published via [code]expert

https://expert.ethz.ch

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 14 / 38

slide-37
SLIDE 37

Projects

During the semester, you work on a few small projects The project tasks will be published via [code]expert

https://expert.ethz.ch

You work on the tasks on your own The exercise hours are meant for answering your questions Presentation of the solutions via the PELE system

https://pele.ethz.ch

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 14 / 38

slide-38
SLIDE 38

Projects

The projects will be presented in the exercise hours

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 15 / 38

slide-39
SLIDE 39

Projects

The projects will be presented in the exercise hours Presentation and discussion with assistants via Zoom Teams of 2 students each Grading by assistants, feedback by students

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 15 / 38

slide-40
SLIDE 40

Projects

The projects will be presented in the exercise hours Presentation and discussion with assistants via Zoom Teams of 2 students each Grading by assistants, feedback by students Presentation is mandatory but without effect on the grade

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 15 / 38

slide-41
SLIDE 41

Projects

The projects will be presented in the exercise hours Presentation and discussion with assistants via Zoom Teams of 2 students each Grading by assistants, feedback by students Presentation is mandatory but without effect on the grade [code]expert allows you to test your solution before handing it in

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 15 / 38

slide-42
SLIDE 42

Python Tutorial

Easy introduction to Python, no previous knowledge necessary Time needed: roughly two hours

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 16 / 38

slide-43
SLIDE 43

Python Tutorial

Easy introduction to Python, no previous knowledge necessary Time needed: roughly two hours Tutorial website

https://et.lecturers.inf.ethz.ch/subscriber/course/ 5TLRsNXvLcMaw229P

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 16 / 38

slide-44
SLIDE 44

Introduction to Python

slide-45
SLIDE 45

Programming Tools

Editor: Program to modify, edit and store Python program texts

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 17 / 38

slide-46
SLIDE 46

Programming Tools

Editor: Program to modify, edit and store Python program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 17 / 38

slide-47
SLIDE 47

Programming Tools

Editor: Program to modify, edit and store Python program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively) Computer: Machine to execute machine language programs

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 17 / 38

slide-48
SLIDE 48

Programming Tools

Editor: Program to modify, edit and store Python program texts Compiler: Program to translate a program text into machine language (intermediate code, respectively) Computer: Machine to execute machine language programs Operating System: Program to organize all procedures such as file handling, editing, compiling, and program execution

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 17 / 38

slide-49
SLIDE 49

English vs. Programming Language

English “Science is what we understand well enough to explain to a computer. Art is everything else we do. ”

DONALD KNUTH

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 18 / 38

slide-50
SLIDE 50

English vs. Programming Language

English “Science is what we understand well enough to explain to a computer. Art is everything else we do. ”

DONALD KNUTH

Python

# computation b = a * a # b = a**2 b = b * b # b = a**4

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 18 / 38

slide-51
SLIDE 51

Syntax and Semantics

Like our language, programs have to be formed according to certain rules

Syntax: Connection rules for elementary symbols (characters) Semantics: Interpretation rules for connected symbols

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 19 / 38

slide-52
SLIDE 52

Syntax and Semantics

Like our language, programs have to be formed according to certain rules

Syntax: Connection rules for elementary symbols (characters) Semantics: Interpretation rules for connected symbols

Corresponding rules for a computer program are simpler, but also more strict because computers are relatively stupid

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 19 / 38

slide-53
SLIDE 53

Kinds of Errors Illustrated with English Language

The car drove too fast.

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-54
SLIDE 54

Kinds of Errors Illustrated with English Language

The car drove too fast.

Syntactically and semantically correct

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-55
SLIDE 55

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat.

Syntactically and semantically correct

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-56
SLIDE 56

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat.

Syntactically and semantically correct Syntax error: word building

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-57
SLIDE 57

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is.

Syntactically and semantically correct Syntax error: word building

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-58
SLIDE 58

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is.

Syntactically and semantically correct Syntax error: word building Syntax error: word order

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-59
SLIDE 59

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat

Syntactically and semantically correct Syntax error: word building Syntax error: word order

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-60
SLIDE 60

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking, my dog, and my cat.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-61
SLIDE 61

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-62
SLIDE 62

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-63
SLIDE 63

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-64
SLIDE 64

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- cally wrong: wrong article [type error]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-65
SLIDE 65

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car. The bike gallops fast.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- cally wrong: wrong article [type error]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-66
SLIDE 66

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car. The bike gallops fast.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- cally wrong [run-time error]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-67
SLIDE 67

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car. The bike gallops fast. We saw her duck.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- cally wrong [run-time error]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-68
SLIDE 68

Kinds of Errors Illustrated with English Language

The car drove too fast. Thecar drove too fsat. Red the car is. I find inspiration in cooking my dog and my cat She is not tall and red-haired. I own an red car. The bike gallops fast. We saw her duck.

Syntactically and semantically correct Syntax error: word building Syntax error: word order Syntax error: missing punctuation marks Syntactically correct, but ambiguous [no analogon] Syntactically correct, but gramatically and semanti- cally wrong: wrong article [type error] Syntactically and gramatically correct, but semanti- cally wrong [run-time error] Syntactically and sematically correct, but ambiguous [no analogon]

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 20 / 38

slide-69
SLIDE 69

Introduction to Python

Used Software

slide-70
SLIDE 70

Used Software

There are numerous Python development environments (IDEs) These contain an editor and several tools

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 21 / 38

slide-71
SLIDE 71

Used Software

There are numerous Python development environments (IDEs) These contain an editor and several tools We use [code]expert

https://expert.ethz.ch

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 21 / 38

slide-72
SLIDE 72

Used Software

There are numerous Python development environments (IDEs) These contain an editor and several tools We use [code]expert

https://expert.ethz.ch

Also recommended (offline): PyCharm Education

https://www.jetbrains.com/pycharm-educational/download/

Download the Community Edition

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 21 / 38

slide-73
SLIDE 73

Introduction to Python

A First Python Program

slide-74
SLIDE 74

A First Python Program

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x # y is the square of x print("The value of y is", y) z = y*y # z is the square of y print("The value of z is", x*x*x*x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 22 / 38

slide-75
SLIDE 75

Behavior of a Program

At compile time Program accepted by the compiler (syntactically correct) Compiler error

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 23 / 38

slide-76
SLIDE 76

Behavior of a Program

At compile time Program accepted by the compiler (syntactically correct) Compiler error During runtime correct result incorrect result program crashes program does not terminate (endless loop)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 23 / 38

slide-77
SLIDE 77

Comments

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x # y is the square of x print("The value of y is", y) z = y*y # z is the square of y print("The value of z is", x*x*x*x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 24 / 38

slide-78
SLIDE 78

Comments

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x # y is the square of x print("The value of y is", y) z = y*y # z is the square of y print("The value of z is", x*x*x*x)

Comments

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 24 / 38

slide-79
SLIDE 79

Comments and Layout

Comments are contained in every good program document, what and how a program does something and how it should be used are ignored by the compiler Syntax: # until the line end

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 25 / 38

slide-80
SLIDE 80

Comments and Layout

Comments are contained in every good program document, what and how a program does something and how it should be used are ignored by the compiler Syntax: # until the line end Please note empty lines are ignored Python dictates indentations that reflect the program logic

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 25 / 38

slide-81
SLIDE 81

Introduction to Python

Statements

slide-82
SLIDE 82

Statements

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 26 / 38

slide-83
SLIDE 83

Statements

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x) statements

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 26 / 38

slide-84
SLIDE 84

Statements

Statements are building blocks of a Python program are executed (sequentially) are given in one line

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 27 / 38

slide-85
SLIDE 85

Statements

Statements are building blocks of a Python program are executed (sequentially) are given in one line Any statement (potentially) provides an effect

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 27 / 38

slide-86
SLIDE 86

Statements – Values and Effects

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 28 / 38

slide-87
SLIDE 87

Statements – Values and Effects

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x)

Effect: Output of the string This is... Effect: Variable x is created and assigned value 20

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 28 / 38

slide-88
SLIDE 88

Introduction to Python

Variables

slide-89
SLIDE 89

Fundamental Types

Variables represent (varying) values integers real numbers (float) strings . . .

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 29 / 38

slide-90
SLIDE 90

Fundamental Types

Variables represent (varying) values integers real numbers (float) strings . . . In contrast to, for example, Java or C, the type is not explicitly stated when a variable is declared (used for the first time)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 29 / 38

slide-91
SLIDE 91

Introduction to Python

Expressions

slide-92
SLIDE 92

Expressions

Expressions represent computations

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 30 / 38

slide-93
SLIDE 93

Expressions

Expressions represent computations are either primary (x)

  • r composed (x * x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 30 / 38

slide-94
SLIDE 94

Expressions

Expressions represent computations are either primary (x)

  • r composed (x * x)

. . . from different expressions by operators . . . and parentheses

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 30 / 38

slide-95
SLIDE 95

Expressions

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x )

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 31 / 38

slide-96
SLIDE 96

Expressions

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x ) Variable name, primary expression

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 31 / 38

slide-97
SLIDE 97

Expressions

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x ) Composite expression

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 31 / 38

slide-98
SLIDE 98

Expressions

represent computations are primary or composite (by other expressions and operations) Example a * a is composed of

variable name, operator symbol, variable name variable name: primary expression

can be put into parentheses

a * a can be written as (a * a)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 32 / 38

slide-99
SLIDE 99

Introduction to Python

Operators and Operands

slide-100
SLIDE 100

Operators and Operands

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 33 / 38

slide-101
SLIDE 101

Operators and Operands

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x) Left operand (variable) Right operand (expression)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 33 / 38

slide-102
SLIDE 102

Operators and Operands

print("This is a Python program") x = 20 print("The value of x is", x) y = x*x print("The value of y is", y) z = y*y print("The value of z is", x*x*x*x) Assignment operator Multiplication operator

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 33 / 38

slide-103
SLIDE 103

Operators

Operators make expressions (operands) into new composed expressions have an arity Example (Multiplication) a * a Operand a, Operator * , Operand a

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 34 / 38

slide-104
SLIDE 104

Multiplication Operator *

Multiplication operator expects two R-values of the same type as operands (arity 2) “returns the product as value of the same type, ” that means formally: The composite expression is value of the product of the value of the two

  • perands

Examples

a * a b * b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 35 / 38

slide-105
SLIDE 105

Assignment Operator =

Assigns to the left operand the value of the right operand and returns the left

  • perand

Examples

b = b * b a = b

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 36 / 38

slide-106
SLIDE 106

Assignment Operator =

Assigns to the left operand the value of the right operand and returns the left

  • perand

Examples

b = b * b a = b

Attention The operator "‘="’ corresponds to the assignment operator of mathematics (:=), not to the comparison operator (=)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 36 / 38

slide-107
SLIDE 107

Exercise – Celsius to Fahrenheit Calculator

Write a program that interprets a number (like, e. g., 31) as a temperature in degree Celsius

  • utputs the same temperature in

degree Fahrenheit uses the formula fahrenheit = 9 · celsius

5 + 32

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 37 / 38

slide-108
SLIDE 108

Exercise – Celsius to Fahrenheit Calculator

celsius = 31 fahrenheit = 9 * celsius / 5 + 32 print(fahrenheit)

Digital Medicine I – Introduction to the Course Autumn 2020 Böckenhauer, Komm 38 / 38

slide-109
SLIDE 109

Thanks for your attention