0% found this document useful (0 votes)
10 views18 pages

Ex3 AI and Python

The document covers debugging in Python, highlighting common issues such as missing library imports. It explains conditional statements, including 'if' and 'if-else', and emphasizes the importance of indentation in Python syntax. Additionally, it introduces comparison and relational operators used in conditional evaluations.

Uploaded by

s14529211
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)
10 views18 pages

Ex3 AI and Python

The document covers debugging in Python, highlighting common issues such as missing library imports. It explains conditional statements, including 'if' and 'if-else', and emphasizes the importance of indentation in Python syntax. Additionally, it introduces comparison and relational operators used in conditional evaluations.

Uploaded by

s14529211
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

AI and Python

Lesson 3
除錯 (Debug)

• 試指出導致以下程式無法運行的原因。 Page22

沒有匯入函數庫 (Library)。

2
Debug

• 試指出導致以下程式無法運行的原因。 Page22

使用了相關函數後
才匯入函數庫。

3
測試站 1.1 Page 26
2. C
1. A

3. D
4
Conditional Statements

• A conditional statement lets the program


make evaluations based on the specified
condition.

• The logical result will decide which statements


the program should execute. A conditional
evaluation only has two possible results:
True or False.

5
“If” Conditional Statements
1
●Write your program according to the figure below.

[Link]

[Link]
[Link]

6
“If” Conditional Statements

• The code in the “if” body will only be executed when the condition is satisfied
otherwise, the code will be ignored and this conditional statement ends.

7
Comparison Operators
● compare the values on
both sides
● ✅values, variables and
mathematical operators
on both sides.
Which string is shown in the
Conditional Statement shell? Hello World! or
Goodbye World! , why ?
1. Write the program.

[Link] 2

use == instead of = to
compare if two values are equal.
Conditional Statement
[Link]
Change your program
Only four characters are printed.
What are they? 2

A consequent can include


more than one line of code. ● Press Tab to add an indent.
👆🏻use indents to indicate ● select multiple lines, press Tab
or Shift + Tab to add/
which line is a part of the remove indents for all
consequent. selected lines respectively.
“if-else” Conditional Statements 3
• The code in the “if” body will only be executed when the condition is satisfied;
otherwise,
• When the evaluation result of the condition is False, the code in the “if” body
will be ignored and the code in the “else” body will be executed.

[Link]

11
Relational Operators

• When we use conditional statements, we can pair them with relational operators to
compare the values on both sides and evaluate the condition

12
Indentation

• Indentation is a very important syntax in Python. It shows the logical structure of


the program by indicating the branch to which the statements belong.

13
Conditional Statement 4
[Link]
Create a new program
according to the
right figure.

Run the program. What do you see in the shell?


Mission Time

16
Mission Time
● Task1: Currency_Converter

17
Mission Time

18

You might also like