HOW TO RUN PYTHON PROGRAM IN COMMAND PROMPT? ============================================ 1) start the command prompt 2) need to use "cd" command Syntax: cd folder_path the above command can navigate you to the file location 3) run the corresponding file using the command "python". SYntax: python file-name.py # WAP TO PRINT ALL 4-DIGIT AMSTRONG NUMBERS. AMSTRONG NUMBER: ================ THE SUM OF EQUIVALENT LENGTH'S POWERS OF INDIVIDUAL DIGITS IS EQUALS TO ORIGINAL NUMBER ==> AMSTRONG NUMBER EX: ABC A^3 + B^3 + C^3 == ABC ABCD A^4 + B^4 + C^4 + D^4 == ABCD 4-DIGIT AMSTRONG NUMBERS ARE IN BETWEEN 1000 TO 9999 1000 ==>1^4 + 0^4 + 0^4 + 0^4 ==> 1 == 1000 WRONG 1001 1002 NESTED LOOPS LOOP WITH CONDITIONS for num in range(1000,10000): # need to define the logic of armstrong number for each number n = num # initialization 1234 result = 0 while n != 0: ind_dig = n % 10 # 4 3 2 1 powers = ind_dig ** 4 # 256 81 16 1 result += powers # 256 337 353 354 n = n // 10 # 123 12 1 0 if result == num: print(num,end = "\t") ========================================================================== Infinite loops: =============== the loop can execute infinitely 1) when the condition is incorrect 2) when the update statement is missing 3) when the update statement is incorrect. # incorrect condition ===================== i = 1 while i >= 1: print(i) i = i + 1 ======================= # missing of update statement ============================== i = 1 while i <= 10: print(i) ====================================== # incorrect update statement ============================= i = 1 while i <= 10: print(i) i -= 1 ====================================== Applications of Infinite Loops: ================================ 1) Gaming Applications car race: start the car with speed: 10kmph increase to 20 kmph 30 40 50....... cards 2) Network Communication Applications ex: Smartphone ==> Jio started call ===> destination user 7.00 am ====> 8.30 =================> =================> ==================> <================== <================== ===================> ================================================== Transfer Statements =================== 1) when we want to stop executing the loop uncertainly 1 to 10 during the 5th iteration: stop the execution 2) when we want to pause/skip the loop with only one iteration and continue with remaining iterations 1 to 10 1 to 4 ==> take 5th iteration ==> stop/pause 6 to 10 ==> continue There are two types of transfer statements: 1) break 2) continue 1) break statement: =================== ==> when we want to terminate the loop execution immediately Syntax: break for i in range(1,11): if i == 6: break print(i,end = "\t") 2) continue statement ===================== ==> when we want to skip the specific iteration and continue with remaining, continue is used. Syntax: continue for i in range(1,11): if i == 6: continue print(i,end = "\t") Note: ==== All the transfer statements can always define in loops only along with conditions. With out conditions: ==================== while i <= 10: print(i,end = "\t") i += 1 break ======================= i = 1 while i <= 10: print(i,end = "\t") i += 1 continue ===================================== Note: ==== No switch statement in python