The if statement
Until now your programs ran all their lines, one after the other. With conditions the program can decide : it runs a block of…
Immerse yourself in the captivating world of control structures and conditions in programming with this lesson. You will discover how to leverage these crucial tools to make decisions in your programs and efficiently manage the flow of execution. This lesson provides you with the essential skills to develop programs with logical and effective decision-making. Enhance your programming proficiency through hands-on exercises and take another stride in your journey towards mastering control structures and conditions.
Until now your programs ran all their lines, one after the other. With conditions the program can decide : it runs a block of…
A lone if only acts when the condition is true. To choose between two or more paths you add else and elif .
Many decisions depend on more than one thing at once. Logical operators let you combine conditions into one.
Inside the block of an if you can write another if . This is called nesting conditions, and it is used to make decisions on…
When an if/else is only used to choose between two values, Python lets you write it on a single line. It is called the…
Conditions are simple, but they have traps that almost everybody falls into at first. These are the most common mistakes and how…
Since Python 3.10 there is the match statement, which compares a value against a series of patterns and runs the first one that…
Write a Python program that functions as a basic calculator. The program will prompt the user to input two numbers and a…
Develop a Python program to determine and display the absolute value of a number, whether it is positive or negative.
Write a Python program that asks the user to enter a number (x). The program should determine whether this number is positive or…
Create a Python program that prompts the user for a letter x and checks whether it is a vowel or any other symbol. The program…
Create a Python program that uses the conditional operator ( and ) to assign a value to a boolean variable. Assign True if both…
Write a Python program that prompts the user to enter three numbers (x, y, z) and determines which of them is the largest number…
Create a Python program that prompts the user for two numbers and responds whether they are positive or if both are positive…
Create a Python program that prompts the user to enter two integers (a, b) and determines how many of them are positive using…
Create a Python program that calculates a student's grade based on an integer input. Request a number (x) from the user and…
A year is a leap year if it is divisible by 4, except century years (divisible by 100), which are only leap years if they are…
Three lengths form a triangle only if each side is smaller than the sum of the other two . If they do, it is classified by its…
In the game of rock, paper, scissors , rock beats scissors, scissors beat paper and paper beats rock. If both choose the same, it…
FizzBuzz is a classic for practicing conditions: depending on the divisors of the number, one word or another is shown. The order…
The price of a shipment depends on the bracket in which the weight of the package falls. The conditions are evaluated in order…
The match statement (Python 3.10 or later) compares a value against several patterns , even structures such as lists. It is ideal…