Blog Detail

September 1, 2023

Python Conditionals Exercises

  • If the heart rate is below 60 or above 100, then activate the ICU alarm.

                    heart_rate = 45
    
    if heart_rate < 60 or '':
        print('Activate the ICU alarm!')
  • Write an if condition in Python to check if an employee's salary falls within a specific salary range for a bonus calculation.

                    salary = 50000
    
    min_salary = 40000
    max_salary = 60000
    
    if salary '' min_salary and salary <= max_salary:
        print("You are eligible for a bonus calculation.")
    <= >= >
  • This code determines the mortgage eligibility based on income and credit score.
    What will be the value of the eligibility variable?

                    income = 50000
    credit_score = 900
    
    if income >= 50000 and credit_score >= 700:
        eligibility = "Eligible"
    elif income >= 40000 and credit_score >= 650:
        eligibility = "Partially Eligible"
    else:
        eligibility = "Not Eligible"
    
    
    print(eligibility)
  • This code determines the mortgage eligibility based on income and credit score.
    What will be the value of the eligibility variable?

                    income = 90000
    credit_score = 900
    
    if income >= 50000 and credit_score >= 700:
        eligibility = "Eligible"
    elif income >= 40000 and credit_score >= 650:
        eligibility = "Partially Eligible"
    else:
        eligibility = "Not Eligible"
    
    
    print(eligibility)
  • This code determines the mortgage eligibility based on income and credit score.
    What will be the value of the eligibility variable?

                    income = 35000
    credit_score = 1200
    
    if income >= 50000 and credit_score >= 700:
        eligibility = "Eligible"
    elif income >= 40000 and credit_score >= 650:
        eligibility = "Partially Eligible"
    else:
        eligibility = "Not Eligible"
    
    
    print(eligibility)
  • What does the condition of the if statement mean?

                    product_code = '100001'
    
    if product_code.isdigit() and len(product_code) == 6:
        print("Valid product code.")
    else:
        print("Invalid product code. Please enter a numeric value.")
  • Python Exercises for Conditionals

    • If you've faced difficulties with these exercises, take a look at Conditionals Module on my Python course.


    You can also share 'Python Conditionals' Exercises on your:
    X (Twitter) - Telegram - Linkedin - Facebook - or on your favorite platform...




    Happy Coding!
    Behnam Khani