![]() Repetition of a set of statements in a program ![]() This kind of repetition is also called iteration. Whenever we need to execute same statement again and again in a program, it comes in the category of repetition. Print("Largest number is : ", num3) Click for more questions on if-else Print("Largest number is : ", num2) else: Print("Largest number is : ", num1) elif num2 > num1 and num2 > num3: Num3 = int(input("Enter Third number: ")) if num1 > num2 and num1 > num3: Num2 = int(input("Enter Second number: ")) num1 = int(input("Enter any number: "))Įxample 7: Write a program to accept three numbers from the user and display the largest number num1 = int(input("Enter First number: ")) “Sunday” for 7 num1 = int(input("Enter any number"))Įxample 6 : Write a program to check whether a number is positive, negative, or zero. The syntax for a selection structure using elif is as shown below: if condition:Įxample 5 : Write a program to accept a number from the user (between 1 and 7) and display the name of the day like display “Monday” for 1, “Tuesday” for 2 …………………. num1 = int(input("Enter First number"))Įxample 4 : Write a program check whether a number is even or odd. The syntax for if.else statement is as follows.Įxample 2 : Accept age from the user and display a message “Hello” if the age is greater than 18 otherwise display message “Bye” age = int(input("Enter your age "))Įxample 3 : Write a program to find the positive difference between two numbers accepting from user. The syntax of if statement is: if condition:Įxample 1 : Write a program to check whether a person’s age is greater than 18. In programming, this concept of decision making or selection is implemented with the help of if.else statement. A decision involves selecting from one of the two or more possible options. When we use Google map or any other direction services, to reach from one place to another, we notice that sometimes it shows more than one path like the least crowded path, shortest distance path, etc. Python supports two types of control structures-selection and repetition SELECTION The order of execution of the statements in a program is known as flow of control. #In above program all the statements are executed in sequence for example #Program to add three numbers n1 = int(input("Enter first number")) ![]() Till now we are writing those programs in Python where Python executes one statement after another from beginning to the end of the program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |