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

Classification of computer based on their cost size and confriguration.

TYPES OF COMPUTER Computer and it's Type Computers are classified by the type of data they are desinged to process. Data may be obtained either as a result of countig of through the use of same measuring instrument. Data that are obtained by counting are called discreate data are total numbers of students in a classroom. Data that must be obtained throgh measurement are called continous data. For example, continious data are the speeds an automobile measure by speedmotor or the tempreature of a patient as masured by a thermometer. Classification of computer based on their cost size and confriguration. In this category computers are classified as micro-computer. mainfraim compute...

history of computer.

History of Computer The ENIAC was invented by J. Presper Eckert and John Mauchly at the University of Pennsylvania and began construction in 1943 and was not completed until 1946. It occupied about 1,800 square feet and used about 18,000 vacuum tubes, weighing almost 50 tons. When was the first computer invented? There is no easy answer to this question due to the many different classifications of computers. The first mechanical computer, created by Charles Babbage in 1822, doesn't really resemble what most would consider a computer today. Therefore, this document has been created with a listing of each of the computer firsts, starting with the Difference Engine and leading up to the computers we use today. NOTE: Early inventions which helped lead up to the computer, such as the abacus, calculator, and tablet machines, are not accounted for in this document. First mechanical computer or automatic computing engine concept In 1822, Charles Babbage conceptualized and b...

What is Python ?

What is python What is Python: - Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python was developed by Guido Van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands. Features of Python:-  Less line of codes than other languages (fast execution)  Platform independent  Open Source  Object Oriented  It supports functional and structured programming methods  It can be used as a scripting language or can be compiled to byte-code for building large applications  It provides very high-level dynamic data types and supports dynamic type checking  It supports automatic garbage collection  It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java How to start the Python? First of all install the Python 2.7.12 on your system. After installation it will create a directory in C: drive named Python27. In Python27...