Logic Flow: if condition

Beginning Python Programming

Makzan, 2020 April.

if condition

  • Using if block
  • indentation

Code example: if

score = 61

if score >= 60:
    print("Pass")
else:
    print("Fail")

Indentation: 4 spaces

score = 61

if score >= 60:
    print("Pass")
else:
    print("Fail")

Code example: if

age = input("What is your age? ")

if int(age) >= 18:
    print("You may drink, a little bit.")
else:
    print("Please don't drink.")

print("Good bye.")

Code example: if + function

def is_student_pass(score):
    if score >= 60:
        return "Pass"
    else:
        return "Fail"

print(is_student_pass(59))
print(is_student_pass(62))

# Results:
> Fail
> Pass

if condition

  • Using if block
  • indentation

Summary

Python: if condition

By makzan

Python: if condition

  • 467