Skip to main content

Use of statement in python

Use of statement of Python:


Use of if – else statement:-if – else is the variation of if statement. We attach condition with if statement if given condition is true then if block code will executed and if the given condition is false then else block code will executed.

The syntax of if – else statement is given below:-
if condition:

Statement 1
Statement 2
else:
Statement 3
Statement 4
Write a program in python to check the given number is even or odd.
n=input(“Enter a number : ”)
if n%2==0:
print “The number ”,n,”is even”
else:
print “The number”,n,”is odd”

Use of if-else ladder:-



In Python language the switch statement is not worked. In Python we use if-else ladder in spite of using switch.

The syntax of if-else ladder is given below:-

if condition1:
Statement 1
elif condition 2:
Statement 2
elif condition 3:
Statement 3 >br> else:
Statement 4
Write a program in python to find greatest number in three numbers.
a=input(“Enter first number : ”)
b=input(“Enter second number : ”)
c=input(“Enter third number : ”)
if a>b and a>c:
print “Greatest Number = ”,a
elif b>a and b>c:
print “Greatest Number = ”,b
else:
print “Greatest Number = ”,c


Develop a program in Python to calculate bill after taking units from user. Take the following logic to calculate the electricity bill; For 1 to 150 units rate is Rs. 2.40, for next 150 (150 to 300) units rate is Rs. 3.00 and Rs. 3.20 for units above 300.



unit=input(“Enter the number of units consumed : ”)
if unit<=150:
bill=unit*2.40
elif unit>150 and unit<=300:
bill=(150*2.40)+(unit-150)*3
else:
bill=(150*2.40)+(150*3)+(unit-300)*3.20
print “Your bill = ”,bill
Iteration Statements in python:-
while loop:- The while is a keyword in python which works as loop control. The syntax of while loop is



Comments

Popular posts from this blog

computer and it's generation

Computer and It's GENERATION Let us first define the term computer. Computer is defined in the Oxford dictionary as "An automatic electronic apparatus for making calculations or controlling operations that are expressible in numerical or logical terms." The definition clearly categorise computer as electronic apparatus although the first computers were mechanical and electromechanical apparatus. The definition is also pointing towords the two major areas of computer application viz. data processing and computer assisted controls/operations. The another important confluence of the definition is the fact that the computer can perform only those operations/calculations which can be expressed in logical or numerical terms. Computer Generation From the early 1940's to the present, Computer scientists have been able to identify clear-cut stages in the development of computer technology. With each stage, radical change in electronics have taken place. As a resu...

Introduction of C Language

Introduction of C The C programming language is a genera-purpose, high-level language (generally denoted as structured language). C programming languages was at first developed by Dennis M.Richie at At&T Bell Labs. C is one of the most commonly used programming languages. It is simple and efficient therefore it become best among all. It is used in all extends of application, mainly in the software development. Many software's & application as well as the compilers for other programming language are written in C also Operating Systems like Unix, Dos and Windows are written in C. C has many powers, it is simple, stretchy and portable, and it can control System Hardware easily. It is also one of the few languages to have an international standard, ANSI C. Advantages of C 1. Fast Powerful & efficient 2. Easy to learn. 3. It is portable. 4. "Mid-level" Language 5. Widly accepted language 6. Supports modular programming style. 7. useful for all ...