if else example

Sword Code
0
While executing an program, if else is use to give choice wheater to do some thing or not. It is use to give simple choice and as well as complex choices such as like in simple calculator or in comparison, calculating the tax according to employee pay etc.,

while using python function like loop, if else or if else-if or any other donot cancel space that is made automatically when you use keywords. reason is, that default space tells the language that these line of code are the part of that keyword when you remove the space by even one space that languag will not detect it as a part other than the the keyword.



In python this is one common issue that accours while using the language. For instance,  while using if else or any other statement like if else-if, switch or for loop etc. This can be seen in the code given below


The example is give below

Examples:

The example are sonario based. In this i will show you three different sonerio based program 

Example 1

Create a program that input income from user in float data type. Such that if the income is greater that 60,000 deduct 15% from the income, and if less that 60,000 deduct 4% from income and display total income, tax and income after tax.



Example 2

Create a program that take a number as an input and tell wheather the number is even or odd


Example 3

Create a program that take input from user and ask the user if he/she enter 1 to confirm the purchase and display message "Thanks for the purchase" or press any other number to decline the purchase


Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*