Introduction to Python Conditions and If Statements in Medical Informatics

Slide Note
Embed
Share

Python allows for user input and supports logical conditions using if-else statements. Learn how to use if, else, elif statements, along with shorthand if-else for decision making in Python programming. Understand how to compare values, execute statements based on conditions, and handle different scenarios with practical examples.


Uploaded on Sep 12, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 1stGrade Introduction to Medical Informatics Python Conditions and If statements By: Fatima Thaer

  2. 01 Python Conditions and If statements

  3. User input Python allows for user input. That means we are able to ask the user for input. for example: username = input("Enter username:") print("Username is: " + username) output Username is: Dani Another example: Age = input("Enter your age:") print( My age is: " + Age) output My age is: 22

  4. IF. Else

  5. IF. Else Python supports the usual logical conditions from mathematics: Equals: a == b Not Equals: a != b Less than: a < b Less than or equal to: a <= b Greater than: a > b Greater than or equal to: a >= b Note: These conditions can be used in several ways, most commonly in "if statements" and loops.

  6. IF. Else a = 33 b = 200 if b > a: print("b is greater than a") output b is greater than a a = 200 b = 33 if b > a: print("b is greater than a") else: print("b is not greater than a") output b is not greater than a

  7. IF. ElseElif a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") output a is greater than b

  8. IF. ElseElif You can also have an else without the elif: a = 200 b = 33 if b > a: print("b is greater than a") else: print("b is not greater than a") output b is not greater than a

  9. Short Hand IF. Else

  10. If you have only one statement to execute, you can put it on the same line as the if statement. For example: a = 2 b = 330 print("A") if a > b else print("B") output B a = 330 b = 330 print("A") if a > b else print("=") if a == b else print("B") output =

  11. Short Hand IF. Else a = 200 b = 33 c = 500 if a > b and c > a: print("Both conditions are True") output Both conditions are True

  12. Assignment 1 Input 2 degrees by adding manually if the first degree grater than 50 or equal print Succecful else fewer than 50 print faild Deadline: 03/02/2024

  13. Thank you Do you have any question!

Related


More Related Content