Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ If-Else Statements | If-Else Statements
Python Ninja copy from video course
セクション 5.  1
ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

If-Else Statements

メニューを表示するにはスワイプしてください

Understanding If-else Statements

An if-else statement evaluates a condition and executes a block of code if the condition is true. If the condition is false, it can execute an alternative block of code. This is how we can make our programs respond differently to different situations.

Here's the basic structure of an if-else statement:

12345
condition = True if condition: print("Condition is true") else: print("Condition is false")

The not Keyword

The not keyword is used to negate a boolean expression. If a condition is true, using "not" will make it false, and vice versa. This can be very useful when you want to execute code only when a condition is not met.

123
condition = False if not condition: print("Condition is false")

Look at an example that uses if-else statements to help our ninja collect all the sushi on the map. The ninja will move around the grid, picking up sushi while avoiding walls.

ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

The ninja will continue to move and pick up sushi until it encounters walls both above and to the right. The if-else statement checks if there is a wall to the right. If there is, the ninja moves up and picks up sushi. Otherwise, it moves to the right and picks up sushi.

タスク

スワイプしてコーディングを開始

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 5.  1
ninja.py

ninja.py

index.html

index.html

preset.py

preset.py

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt