Python For beginners part 3

If Statements & Math in Python — Interactive Blog

If Statement and Logic in Python

Python's if statement forms the backbone of logic in code. It lets you branch execution based on whether a condition is True or False.
See: Programiz If Statements

Try It Yourself

number = int(input('Enter a number: ')) if number > 0: print(f'{number} is a positive number.') else: print(f'{number} is not a positive number.')

Quick Quiz


Hi
Nothing is printed
Error

If-Else and Elif

For multiple conditions, try editing and running this code (you can change n below!):

n = 5 if n > 0: print('Positive') elif n == 0: print('Zero') else: print('Negative')

Flowchart Example

If Statement Flowchart

Video Example


Math with Python

Python offers straightforward math operators as well as advanced mathematical tools through its libraries.
Resources: Programiz Python Operators

Arithmetic Operators Table

Operator Name Example
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Modulusx % y
**Exponentiationx ** y
//Floor Divisionx // y

Try Arithmetic Code Live

a = 7 b = 2 print('Sum:', a + b) print('Subtraction:', a - b) print('Multiplication:', a * b) print('Division:', a / b) print('Floor Division:', a // b) print('Modulo:', a % b) print('Power:', a ** b)

Interactive: Advanced Math Functions

import math print(math.sqrt(25)) # 5.0 print(math.pi) # 3.141592653589793

See the official math docs for more.

Concept Video


Recommended Python Resources

Interactive code powered by PyScript. Quizzes built with JavaScript.
For full interactive blog tech, see this guide.

Comments

  1. simple explanation makes it more easy

    ReplyDelete
  2. nice bhai pehli baari m aadhi chiize clear ho gayi

    ReplyDelete
  3. Its very helpful guys

    ReplyDelete
  4. perfect buddy!!!
    best blogs
    i recommend for everyone starting out as a begginer

    ReplyDelete
  5. Great work
    I really appreciate your hard work and creativity

    ReplyDelete
  6. Phir se BAHAN KE LAUWDE!!!
    yeh harkatein kar rha hai, main *HASTHAMAITHUN* bhi na karu teri website pe, apni GAND se gandi website apni hi GAND mein daal ke nikal ja....

    ReplyDelete
  7. BHENCHOD CHI BHAI !!!!!! YE KYA CHOD WEBSITE HAI ISSE ACCHA TOH MAI WHISPER KI AD MAI PAD KA ROLE KARLU., THU CHI !!!

    ReplyDelete

Post a Comment

Popular posts from this blog

Python For Beginers

Python for Beginner