Control Statements: =================== 1) Conditional Statements 2) Iterative Statements 3) Transfer Statements Conditional Statements: ======================= statements ==> program ==> sequential execution ==> statement by statement based on the condition: these statements can decide the block of code which want to execute and the block of code which want to not execute. ex: program{ block-1{ } block-2{ } } ex: program{ stat1 stat2 stat3 .... stat10 } ==> four types of conditional statements: 1) simple if 2) if-else 3) nested if else 4) if elif else block 1) simple if ============ # WAP TO CONVERT THE NUMBER TO POSITIVE IF IT IS ENTERED AS NEGATIVE. num = int(input("Enter a value:")) # num < 0 ==> negative # num > 0 ==> positive if num < 0: num = -num # -97 ==> -(-97) ==> 97 print("After the Conversion the number = ",num) print("Conversion from negative to positive was successful.") print("Bye Bye") ============================================ 2) if-else ========== # WAP TO FIND THE GIVEN NUMBER IS EVEN NUMBER OF ODD NUMBER. # num % 2 == 0 ==> Even # num % 2 != 0 ==> Odd number = int(input("Enter a number:")) # 16 if number % 2 == 0: # 16 % 2 == 0 97 % 2 == 1 print(number," is an even number.") # if block else: print(number," is an odd number.") # else block / ==> quotient in float // ==> quotient in int % ==> remainder ========================================================= 3) Nested if else: ================== if condition1: if condition2: statements else: statements else: if condition3: statements else: statements # WAP TO FIND SMALLEST NUMBER AMONG THREE INTEGERS. n1 = int(input("Enter First value:")) # 12 7 n2 = int(input("Enter Second Value:")) # 21 21 n3 = int(input("Enter Third Value:")) # 7 12 if n1 < n2: if n1 < n3: smaller_number = n1 else: smaller_number = n3 # 7 else: if n2 < n3: smaller_number = n2 else: smaller_number = n3 print("The Smallest Number = ", smaller_number) ============================================================== 4) if elif else ladder: ======================= # WAP TO PRINT THE STUDENT GRADE BY ACCEPTING 5 SUBJECT MARKS. # PERCENTAGE >= 85 ==> "A1" # PERCENTAGE >= 80 AND < 85 ==> "A2" # PERCENTAGE >= 70 AND < 80 ==> "A" # PERCENTAGE >= 65 AND < 70 ==> "B" # PERCENTAGE >= 60 AND < 65 ==> "C" # PERCENTAGE >= 50 AND < 60 ==> "D" # PERCENTAGE >= 40 AND < 50 ==> "E" # PERCENTAGE < 40 ==> FAIL s1 = int(input("Enter first subject marks:")) s2 = int(input("Enter second subject marks:")) s3 = int(input("Enter third subject marks:")) s4 = int(input("Enter forth subject marks:")) s5 = int(input("Enter fifth subject marks:")) total_marks = s1 + s2 + s3 + s4 + s5 print("The Total Marks = ",total_marks) percentage = total_marks // 5 print("The Percentage = ",percentage) if s1 >= 40 and s2 >= 40 and s3 >= 40 and s4 >= 40 and s5 >= 40: if percentage >= 85: grade = "A1" elif percentage >= 80 and percentage < 85: grade = "A2" elif percentage >= 70 and percentage < 80: grade = "A" elif percentage >= 60 and percentage < 70: grade = "B" elif percentage >= 55 and percentage < 60: grade = "C" elif percentage >= 50 and percentage < 55: grade = "D" elif percentage >= 40 and percentage < 50: grade = "E" else: grade = "Fail" print("The Student Grade = ",grade) else: grade = "Fail" print("The Student Grade = ",grade) ======================================================== Conditional Operator: ===================== Syntax: identifier = Expression-1 if test-condition else Expression-02 # WAP TO PRINT SUM IF FIRST < SECOND OTHERWISE PRINT ITS DIFFERENCE. n1 = int(input("Enter a number:")) n2 = int(input("Enter a number:")) result = (n1 + n2) if n1 < n2 else (n1 - n2) print("The Result = ",result) ========================================================== 1) WAP TO CHECK WHETHER THE GIVEN NUMBER IS POSITIVE OR NEGATIVE NUMBER. 2) WAP TO CHECK WHETHER THE GIVEN YEAR IS LEAP YEAR OR NOT. 3) WAP TO CHECK WHETHER THE PERSON IS ELIGIBLE TO VOTE OR NOT. 4) WAP TO PRINT THE DAY NAME ACCORING TO THE DAY NUMBER. HINT: 1 ==> SUNDAY | 2 ==> MONDAY | 3 ==> TUESDAY ... Website: https://www.ashokit.in/home