Q: WAP IN PYTHON TO ACCESS A YEAR AS AN INPUT AND CHECK WHETHER THAT YEAR IS LEAP YEAR OR NOT. NOTES: ====== 1) YEAR IS NOT DIVIDED WITH '4' ==> NOT LEAP YEAR 2) IF THE YEAR IS DIVISIBLE WITH '4' BUT NOT WITH '100' ==> LEAP YEAR 3) IF YEAR IS DIVISIBLE WITH '4', DIVISIBLE WITH '100' AND ALSO DIVISIBLE WITH '400' ==> LEAP YEAR year = int(input("Enter the year:")) if year % 4 == 0: if year % 100 == 0: if year % 400 == 0: print(year,"is a leap year") else: print(year,"is not a leap year") else: print(year,"is a leap year") else: print(year,"is not a leap year") ========================================================= Q-2: WAP TO MULTIPLY THREE INTEGERS. HOWEVER, IF ONE OF THE NUMBER IS '9' THEN CONSIDER THE VALUES RIGHT TO IT FOR MULTIPLICATION. IF '9' IS THE LAST NUMBER THEN DISPLAY THE OUTPUT AS '-1'. Sample case: =========== Sample Input Sample Output ====================================== 2,4,6 2 * 4 * 6 ==> 48 3,9,2 2 9,7,3 7 * 3 ==> 21 1,4,9 -1 # take three integers as an input number1 = int(input("Enter first number:")) number2 = int(input("Enter second number:")) number3 = int(input("Enter third number:")) result = 0 if number1 == 9: result = number2 * number3 elif number2 == 9: result = number3 elif number3 == 9: result = -1 else: result = number1 * number2 * number3 print("The Result after the multiplication = ",result) ============================================================= ============================================================ Note: ===== from other programming languages: conditional statements: classified into 2-types: 1) If statements 2) Switch statement --> in python: we have only if statements but not switch. Iterative Statements: ===================== -> also called as "Loop Statements". Ex: Print "Hello World!" for 10 times. print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") print("Hello World!") -> instead to write the same amount of code again and again, we can define that particular block for one time and make it execute for several number of times repeatedly as many number of times required, we can use "loop statements" -> there are two types of loop statements: 1) while loop 2) for loop Note: ==== Python does not support "do-while". -> for any loop to work, there are three things are required to define: 1) Initialization 2) Condition 3) Update 1) while loop ============= Syntax: ======= initialization while condition: statement-1 statement-2 update next statement Note: ===== If the update statement is absent, then while loop become infinite. # WAP TO PRINT "HELLO WORLD!" FOR 10 TIMES. line = 1 # initialization while line <= 10: # condition print("Hello World!") line += 1 # update ================================================ Q-2: WAP TO COUNT THE NUMBER OF DIGITS OF A GIVEN NUMBER. Ex: 1234 ==> 4-digit 1 ==> 1-digit number = int(input("Enter an integer:")) count_digits = 0 quotient = number # initialization while quotient != 0: # condition quotient = quotient // 10 count_digits += 1 # update print("The Number of Digits of a number",number,"is = ",count_digits) ============================================================= Assignment: ============== Q-1: ==== WAP TO CALCULATE THE COST FOR THE DELIVERY WITH CERTAIN CONDITIONS: 1) IF THE DISTANCE <= 4KM, THEN DELIVERY CHARGE = 0 2) FOR THE NEXT 4KM, THE DELIVERY CHARGE RS. 5 PER KM. 3) FOR REMAINING, THEN THE DELIVERY CHARGE RS. 7 PER KM. Q-2: ==== WAP TO COUNT THE SUM OF DIGITS OF A NUMBER. Q-3: ==== WAP TO REVERSE THE NUMBER.