• Keine Ergebnisse gefunden

Welcome to the Course

N/A
N/A
Protected

Academic year: 2022

Aktie "Welcome to the Course"

Copied!
105
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Departement Informatik

Basics of CS

Introduction to the Course

Hans-Joachim Böckenhauer Dennis Komm

Autumn 2021 – October 7, 2021

(2)

Welcome to the Course

(3)

Material

Lecture website

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

Moodle Course

https://moodle-app2.let.ethz.ch/course/view.php?id=15450

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 1 / 36

(4)

The Team

Lecturers Hans-Joachim Böckenhauer Dennis Komm

Assistants Daniel Bertschinger Imant Daunhawer Oliver Dudler Silvan Horváth Sara Steiner

(5)

Appointments

Lecture Thursday, 8:15 – 10:00, HG D 7.2

(Additional lecture: 20.10.2021, 14:15 – 16:00, ML F 36) Exercises Monday, 14:15 – 15:45, CAB H 56

Thursday, 10:15 – 12:00, HG D 7.2 Exam Thursday, 16.12.2021

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 3 / 36

(6)

Goal of Today’s Lecture

General information about the lecture The projects, using[code]expert Introduction to algorithms

The first Python program

(7)

Introduction to the Course

Computers and Algorithms

(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?

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]

(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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 5 / 36

(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]

(11)

Algorithm: Central Notion of Computer Science

Algorithm

Method for step-by-step solution of a problem

Execution does not require intellect, only accuracy afterMuhammad al-Chwarizmi;

author of a arabic math book (around 825)

"‘Dixit algorizmi. . . "’ Latin translation [Wikimedia]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 7 / 36

(12)

Algorithm: Central Notion of Computer Science

Algorithm

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

afterMuhammad al-Chwarizmi; author of a arabic

math book (around 825)

"‘Dixit algorizmi. . . "’ Latin translation [Wikimedia]

(13)

Algorithm: Central Notion of Computer Science

Algorithm

Method for step-by-step solution of a problem Execution does not require intellect, only accuracy afterMuhammad al-Chwarizmi;

author of a arabic math book (around 825)

"‘Dixit algorizmi. . . "’ Latin translation [Wikimedia]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 7 / 36

(14)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb6= 0

ifa>bthen a=ab else

b=ba Output:a

(15)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb6= 0

ifa>bthen a=ab else

b=ba Output:a

a b

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 8 / 36

(16)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb6= 0

ifa>bthen a=ab else

b=ba Output:a

a b a b

(17)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb6= 0

ifa>bthen a=ab else

b=ba Output:a

a b a b a b

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 8 / 36

(18)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb6= 0

ifa>bthen a=ab else

b=ba Output:a

a b a b a b a b

(19)

“The Oldest (Known) Non-Trivial Algorithm”

Euclid’s Algorithm

from Euclid’sElements, 300 BC Input: integersa >0,b >0 Output: gcd ofaandb

Input:aandb whileb!= 0:

ifa>b:

a=ab else:

b=ba Output:a

a b a b a b a b

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 8 / 36

(20)

Introduction to the Course

Goals

(21)

1. Computer Science in the Natural Sciences

problem from praxis

computer science problem

solution to comp. science problem

solution to problem from practice

ACTGCAT GGC

ACGCTAAGCACTGCATGGCCAA

ACGCTAAGCACTGCATGGCCAA

modeling

interpretation

comm

unication

between

practice

andcomp. science needs basic knowledge

?

algorithmics, concepts of programming

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 9 / 36

(22)

1. Computer Science in the Natural Sciences

problem from praxis computer science

problem

solution to comp.

science problem solution to problem

from practice

ACTGCAT GGC

ACGCTAAGCACTGCATGGCCAA

ACGCTAAGCACTGCATGGCCAA

modeling

interpretation

comm

unication

between

practice

andcomp. science needs basic knowledge

?

algorithmics,

concepts of programming

(23)

1. Computer Science in the Natural Sciences

problem from praxis computer science

problem

solution to comp.

science problem solution to problem

from practice

ACTGCAT GGC

ACGCTAAGCACTGCATGGCCAA

ACGCTAAGCACTGCATGGCCAA

modeling

interpretation

comm

unication

between

practice

andcomp. science

needs basic knowledge

?

algorithmics,

concepts of programming

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 9 / 36

(24)

1. Computer Science in the Natural Sciences

problem from praxis computer science

problem

solution to comp.

science problem solution to problem

from practice

ACTGCAT GGC

ACGCTAAGCACTGCATGGCCAA

ACGCTAAGCACTGCATGGCCAA

modeling

interpretation

comm

unication

between

practice

andcomp. science needs basic knowledge

?

algorithmics,

concepts of programming

(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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 10 / 36

(26)

2. Computational Thinking

Jeannette Wing

"‘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."’

(27)

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 programmingetc.

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 12 / 36

(28)

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 programmingetc.

(29)

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 programmingetc.

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 12 / 36

(30)

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 programmingetc.

(31)

Introduction to the Course

Projects

(32)

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 Zoom

(33)

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 Zoom

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 13 / 36

(34)

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 Zoom

(35)

Projects

The projects will be presented in the exercise hours

Presentation and discussion with assistants 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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 14 / 36

(36)

Projects

The projects will be presented in the exercise hours

Presentation and discussion with assistants 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

(37)

Projects

The projects will be presented in the exercise hours

Presentation and discussion with assistants 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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 14 / 36

(38)

Projects

The projects will be presented in the exercise hours

Presentation and discussion with assistants 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

(39)

Introduction to Python

(40)

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

(41)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 15 / 36

(42)

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

(43)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 15 / 36

(44)

English vs. Programming Language

English

“Science is what we understand well enough to explain to a computer.

Art is everything else we do.”

DONALDKNUTH

Python

# computation

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

(45)

English vs. Programming Language

English

“Science is what we understand well enough to explain to a computer.

Art is everything else we do.”

DONALDKNUTH

Python

# computation

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 16 / 36

(46)

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

(47)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 17 / 36

(48)

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]

(49)

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(50)

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]

(51)

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(52)

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]

(53)

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(54)

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]

(55)

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(56)

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]

(57)

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(58)

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]

(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

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(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

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]

(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.

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(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.

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]

(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.

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]

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 18 / 36

(64)

Introduction to Python

Used Software

(65)

Used Software

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

We use[code]expert

https://expert.ethz.ch/enroll/AS21/digiMed Also recommended (offline): PyCharm Education

https://www.jetbrains.com/pycharm-educational/download/ (Download the Community Edition)

Another environment is TigerJython

https://webtigerjython.ethz.ch

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 19 / 36

(66)

Used Software

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

We use[code]expert

https://expert.ethz.ch/enroll/AS21/digiMed

Also recommended (offline): PyCharm Education

https://www.jetbrains.com/pycharm-educational/download/ (Download the Community Edition)

Another environment is TigerJython

https://webtigerjython.ethz.ch

(67)

Used Software

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

We use[code]expert

https://expert.ethz.ch/enroll/AS21/digiMed Also recommended (offline): PyCharm Education

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

(Download the Community Edition)

Another environment is TigerJython

https://webtigerjython.ethz.ch

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 19 / 36

(68)

Used Software

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

We use[code]expert

https://expert.ethz.ch/enroll/AS21/digiMed Also recommended (offline): PyCharm Education

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

(Download the Community Edition) Another environment is TigerJython

https://webtigerjython.ethz.ch

(69)

Introduction to Python

A First Python Program

(70)

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)

(71)

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 notterminate(endless loop)

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 21 / 36

(72)

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 notterminate(endless loop)

(73)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 22 / 36

(74)

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

(75)

Comments and Layout

Comments

are contained in every good program

document,whatandhowa 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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 23 / 36

(76)

Comments and Layout

Comments

are contained in every good program

document,whatandhowa 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

(77)

Introduction to Python

Statements

(78)

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)

(79)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 24 / 36

(80)

Statements

Statements

are building blocks of a Python program areexecuted(sequentially)

are given in one line

Any statement (potentially) provides aneffect

(81)

Statements

Statements

are building blocks of a Python program areexecuted(sequentially)

are given in one line

Any statement (potentially) provides aneffect

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 25 / 36

(82)

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:Variablexis created and assigned value 20

(83)

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:Variablexis created and assigned value 20

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 26 / 36

(84)

Introduction to Python

Variables

(85)

Fundamental Types

Variables represent (varying) values integers

real numbers (float) strings

. . .

In contrast to, for example,JavaorC, the type is not explicitly stated when a variable is declared (used for the first time)

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 27 / 36

(86)

Fundamental Types

Variables represent (varying) values integers

real numbers (float) strings

. . .

In contrast to, for example,JavaorC, the type is not explicitly stated when a variable is declared (used for the first time)

(87)

Introduction to Python

Expressions

(88)

Expressions

Expressions

representcomputations

are eitherprimary(x) orcomposed(x * x)

. . . from different expressions byoperators . . . and parentheses

(89)

Expressions

Expressions

representcomputations are eitherprimary(x) orcomposed(x * x)

. . . from different expressions byoperators . . . and parentheses

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 28 / 36

(90)

Expressions

Expressions

representcomputations are eitherprimary(x) orcomposed(x * x)

. . . from different expressions byoperators . . . and parentheses

(91)

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 )

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 29 / 36

(92)

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

(93)

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 29 / 36

(94)

Expressions

representcomputations areprimaryorcomposite

(by other expressions and operations) Example

a * ais composed of

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

can be put into parentheses a * acan be written as(a * a)

(95)

Introduction to Python

Operators and Operands

(96)

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)

(97)

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)

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 31 / 36

(98)

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

(99)

Operators

Operators

make expressions (operands) into new composed expressions have an arity

Example (Multiplication)a * a Operanda, Operator*, Operanda

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 32 / 36

(100)

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 operands

Examples a * a b * b

(101)

Assignment Operator =

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

Examples

b = b * b a = b

Attention

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

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 34 / 36

(102)

Assignment Operator =

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

Examples

b = b * b a = b

Attention

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

(103)

Exercise – Celsius to Fahrenheit Calculator

Write a program that

interprets a number (like, e. g., 31) as a temperature in degree Celsius outputs the same temperature in degree Fahrenheit

uses the formula

fahrenheit= 9·celsius 5 + 32

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 35 / 36

(104)

Exercise – Celsius to Fahrenheit Calculator

celsius = 31

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

(105)

Thanks for your attention

Referenzen

ÄHNLICHE DOKUMENTE

Students achieve a basic understanding of how networks operate and how to build simple local area networks (LAN), perform basic configurations for routers and switches, and

Students achieve a basic understanding of how networks operate and how to build simple local area networks (LAN), perform basic configurations for routers and switches, and

Students achieve a basic understanding of how networks operate and how to build simple local area networks (LAN), perform basic configurations for routers and switches, and

Basics of Computer Science for Human Medicine – Introduction to the Course Autumn 2021 Böckenhauer, Komm 3 / 36.. Goal of

Basics of Computer Science for Human Medicine – Lists, strings, loops Autumn 2021 Böckenhauer, Komm 2 / 21...

Basics of Computer Science for Human Medicine – Lists, strings, loops Autumn 2021 Böckenhauer, Komm 1 / 21.

Basics of Computer Science for Human Medicine – Control Structures Autumn 2021 Böckenhauer, Komm 7 / 36.

Basics of Computer Science for Human Medicine – numpy, matplotlib Autumn 2021 Böckenhauer, Komm 4 /