0% found this document useful (0 votes)
6 views5 pages

Python Programming Basics: Sequential Statements

The document contains several Python programming examples demonstrating sequential statements, including calculations for sum, product, area, and perimeter of rectangles. It also includes conditional statements using if, if-else, and if-elif-else structures to provide feedback based on user input for marks and age. Additionally, it features programs to determine if a number is even or odd and to check if a number is positive, negative, or zero.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Python Programming Basics: Sequential Statements

The document contains several Python programming examples demonstrating sequential statements, including calculations for sum, product, area, and perimeter of rectangles. It also includes conditional statements using if, if-else, and if-elif-else structures to provide feedback based on user input for marks and age. Additionally, it features programs to determine if a number is even or odd and to check if a number is positive, negative, or zero.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON PROGRAMMING

Sequential Statements
Program1
# Sum of two numbers
num1=5
num2=10
sum=num1+num2
print (sum)
Program2
# Product of two numbers
num1=40
num2=60
product=num1*num2
print (product)
Program 3
# Area of rectangle
length=40
breadth=70
area_ rectangle=length*breadth
print (area_ rectangle)
Program 4
#program to take two numbers and then swap them
x=int (input ("Enter value for x:"))
y=int (input ("Enter value for y:"))
x, y=y, x
print ("value of x after swap:" ,x)
print ("value of y after swap:" ,y)

Program 5
#Write a program to print the perimeter and area of a rectangle
L=int (input ("Enter length of the rectangle"))
B=int (input ("Enter breadth of the rectangle"))
P=2*(L+B)
A=L*B
print ("Perimeter of rectangle:", P)
print ("Area of rectangle:", A)
Program 6
If statement
# Write a program that display a message based on the marks
entered by the user
(i) marks=int (input ("Enter marks:"))
if marks<=75:
print ("work harder")
(ii) age=int (input ("enter your age:"))
if age<13:
print ("you are not a teenager")
print (“over”)
Program 7
If -else statement
(i) marks= int (input ("Enter your marks"))
if marks <= 75:
print ("work harder")
else:
print ("You can do better")

ii) CP=int (input ( "enter cost price"))


SP=int (input ("enter selling price"))
if CP>SP:
print("loss")
else:
print("profit")
Program 8
If -elif-else statement
# Write a program that display a message based on the marks
entered by the user
(i) marks=int(input(“enter your marks:))
If marks<=40:
print(“perform better next time.”)
elif marks==50:
print(“you scored fifty percent.”)
elif marks>50:
print(“good”)
else:
print(“invalid input.”)

(ii) age = int(input(“Enter Age”))


if age<16:
print(“You cannot drive”)
elif age==16 and age<18:
print(“You can apply for a learners licence”)
elif age>18:
print(“You can get a driving licence”)
else:
print(“Invalid Input”)

# To input a number and display whether it is even or odd


Num=int(input("Enter a number :"))
if Num%2==0:
print(Num," is even")
else:
print(Num," is odd")
# To input a number and check whether the number is positive or
negative

Num=int(input("enter a number:"))
if Num==0:
print("you entered zero")
elif Num>0:
print("You entered a +ve number")
else:
print("You entered a-ve number")

You might also like