Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

INDEX

NO PROGRAM SIGNATURE

1 Display name and age using print()

2 Read ,marks in 5 subjects and print total, average and percentage

3 Calculate Area and Perimeter of a rectangle

4 Calculate distance using the formula: distance=ut+1/2at2.

5 Calculate Simple interest using formulae (SI=(P*R*T)/100

6 Convert a measurement in feet to inches

7 Print largest among two numbers

8 Check entered number, negative, positive or 0.

9 Swap the entered numbers.

10 Check entered number is an Armstrong number or not

11 Print factorial of a number.

12 Print multiplication table of entered number.

13 Print sum of natural numbers up to n.

14 Print numbers divisible by 7 using for loop.

15 Check entered string is palindrome or not.


Program 1

Aim: Write a python program to display name and age.

Algorithm:

Step 1: Start

Step 2: Read name

Step 3: Read age

Step 4: Display name

Step 5: Display age

Step 6: Stop

Code:

#program to read and display name and age

print(“ What is your name?”)

myName=input()

print(“How old are you?”)

age = int(input())

print(“Hello ” +myName)

print(“ You are “ , age, “year’s old”)

Output:
Program 2

Aim: Write a python program to read name, marks in 5 subjects and print total, average and percentage.

Algorithm:

Step 1: Start

Step 2: Read name

Step 3: Read mark in English, Math, Science, Social and AI

Step 4: Calculate

total= English + Math+ Science+ Social + AI

Step 5: Calculate average

Average=total/5

Step 6: Calculate percentage

Percentage= (Total/500) * 100

Step7: Display name, total, average and percentage

Step8: Stop

Code:

# To print Name, total, average and percentage


print(“ Enter your name”)
name=input()
eng=float(input(“Enter marks in English”))
math=float(input(“Enter marks in Math”))
sci =float(input(“Enter marks in Science”))
soc= float(input(“Enter marks in Social”))
ai= float(input(“Enter marks in AI”))
total= eng+math+sci+soc+ai
Average=total/5
Percentage= (total/500) * 100
print(“Name :” , name)
print(“Total marks : “ , total)
print(“Average : “ , Average)
print(“Percentage : “ , Percentage)
Program 3

Aim: Write a Python program to calculate Area and Perimeter of a rectangle.

Algorithm:

Step 1: Start

Step 2: Read value for length

Step 3: Read value for breadth

Step 4: Calculate area

area=length x breadth

Step 5: Calculate perimeter

perimeter= 2x(length+ breadth)

Step 5: Display area

Step 6: Display perimeter

Step 7: Stop

Code:

L=int(input(" Enter Length:"))


B=int(input("Enter Breadth:"))
Area=L*B
Perimeter=2*(L+B)
print("Area:",Area)
print("Perimeter:",Perimeter)
Program 4

Aim: Write a python program to calculate distance using the formula: distance=ut+1/2at2

Algorithm:

Step 1: Start

Step 2: Read initial velocity, time and acceleration

Step 3: Calculate displacement = initial velocity X time + acceleration X time 2

Step 4: Display displacement

Step 5: Stop

Code:

# Read values for initial velocity, time and acceleration.


u=int(input(“Enter initial velocity”))
t=int(input(“Enter time in seconds”))
a=int(input(“Enter rate of acceleration”))
s= (u * t) + ( ( a* t**2)/2)
print(“Displacement :” , s)

Output:
Program 5

Aim: Write a python program to calculate Simple interest using formulae (SI= (P*R*T)/100.

Algorithm:

Step 1: Start

Step 2: Read Principal amount

Step 3: Read Rate of interest

Step 4Read Time period

Step 5: Calculate Simple interest = (Principal amount X Rate of interest X Time period)/ 100

Step 6 : Stop

Code:

# simple interest
P=float(input(“Enter principal amount:”)
R=float(input(“Enter rate of interest:”))
T=float(input(“Enter time duration:”))
Si=(P*T*R)/100
print(“Simple Interest:”, Si)
Program 6

Aim: . Write a python program to convert a temperature in Celsius into Fahrenheit.

[f=(c*1.8)/32]

Algorithm:

Step 1: Start

Step 2: Read a temperature in Celsius

Step 3: Calculate Fahrenheit = (Celsius X 1.8)/32

Step 4: Display the temperature in Fahrenheit

Step 5: Stop

Code:

C=int(input(“Enter a temperature in Celsius:”))

F=(C*1.8)/32

print(“Temperature in Fahrenheit : “, F)
Program 7

Aim: Write a python program to print largest among two numbers

Algorithm:

Step 1: Start

Step 2: Read Number1 and Number2

Step 3: If Number1 > Number2, go to Step 4 else go to Step 5

Step 4: Print Largest number is Number1

Step 5: Print Largest number is Number2

Step 6: Stop

Code:

a=int(input(“Enter the first number:”))

b=int (input(”Enter the second number:”))

if(a>b):
print(“The largest number is:”, a)
else:
print(“The largest number is:”,b)
Program 8

Aim: Write a python program to Check entered number, negative, positive or 0.

Algorithm:

Step 1: Start

Step 2: Read a number

Step 3: If number > 0 go to step 4 else go to step 5

Step 4: Print entered number is a Positive number go to step 8

Step 5: If number= 0 go to step 6 else go to step 7

Step 6: Print entered number is a Zero go to step 8

Step 7: Print entered number is a negative number

Step 8: Stop

Code:

'''In this program, we check if the number is positive or negative or zero and

display an appropriate message'''

num= int (input(“Enter number”))

if num > 0:

print("Positive number")

elif num == 0:

print("Zero")

else:

print("Negative number")
Program 9

Aim: Write a Python program to Swap the entered numbers.

Algorithm:

Step 1: Start

Step 2: Read two numbers x and y

Step 3: Declare temp

Step 4: temp= x

Step 5: x=y

Step 6: y=temp

Step 7: Display new values of x and y

Step 8: Stop

Code:

X=input(“Enter value for X:”)

Y=input(“Enter value for Y:”)

#create a temporary variable

Temp=X

X=Y

Y=Temp

print(“Value of X after swapping:”,X)

print(“Value of Y after swapping:”,Y)


Program 10

Aim: Write a Python program to Check entered number is an Armstrong number or not

Algorithm:

Step 1: Start

Step 2: Read a number n from user

Step 3: Initialize sum=0 , Temp= n

Step 4: Repeat until Temp > =0

4.1 : sum=sum + cube of last digit

4.2: temp=temp//10

Step 5: If sum==n

Print “Armstrong Number”

Else

Print “ Not Armstrong Number”

Step 6: Stop

Code:

num = int(input(“Enter a number:”))

#initialize sum

sum=0

#sum of cube of each digit

temp=num

while temp>0 :

digit=temp%10

sum=sum + digit**3

temp=temp//10

if num==sum:

print(num,”is an Armstrong number”)

else:

print(num,”is not an Armstrong number”)


Program 11

Aim: Write a python program to Print factorial of a number.

Algorithm:

Step 1: Start

Step 2: Read number num from user

Step 3: Initialize variable fact=1, a=1

Step 4: Repeat until a<=num

4.1 : fact=fact*a

4.2 : a=a+1

Step 5: Print fact

Step 6: Stop

Code:

#read the number

n=int(input(“Enter a number”))

#initalize fact variable

fact=1

#factonial of 0 is complex number

if n<0:

print(“factorial does not exist for negative number”)

#factorial of 0 is 0

elif n==0:

print(“factorial is 0”)

#for all positive numbers

else:

for a in range(1,n+1)

fact= fact * a
#exit for loop

print(“Factorial of the number is”, fact)


Program 12

Aim: Write a python program to print multiplication table of entered number.

Algorithm:

Step 1:Start

Step 2: Read number n from user

Step 3: Repeat from i=1 to 11

3.1: Display the table values ‘num X i= num*i)

Step 4: Stop

Code:

# To take input from the user

num = int(input("Display multiplication table of? "))

# Iterate 10 times from i = 1 to 10

for i in range(1, 11):

print(num, 'x', i, '=', num*i)


Program 13

Aim: Write a python program to print sum of natural numbers up to n.

Algorithm:

Step 1: Start

Step 2: Read value for n

Step 3: Initialize variable sum=0, i=1

Step 4: Repeat until i<=n

4.1: sum=sum + i

4.2: i= i+1

Step 5: Print sum

Step 6: Stop

Code:

# To take input from the user,

n = int(input("Enter n: "))

# initialize sum and counter

sum = 0

i=1

while i <= n:

sum = sum + i

# update counter

i = i+1

# exit loop

print("The sum is", sum)


Program 14

Aim: Write a python program to print numbers divisible by 7 using for loop

Algorithm:

Step 1: Start

Step 2: Read the lower limit, n

Step 3: Initialize i=1

Step 4: Repeat until i=n+1

4.1 :if i % 7=0 go to Step: 4.1 Else go to Step:4.3

4.2: Print i

4.3 : :i=i+1

Step 5 : Stop

Code:

#upper limit

n=int(input(“Enter the last number:”))

for i in range(1,n+1):

if(i%7==0):

print(i)
Program 15

Aim: Write a python program to Check entered string is palindrome or not.

Algorithm:

Step 1: Start

Step 2: Read a string, str

Step 3:Reverse the string, rev_str

Step 4:If str=rev_str then go to 5 else go to 6

Step 5: Print string is palindrome

Step 6: Print string is not palindrome

Step 7: Stop

Code:

print(“ Enter the string”)

str=input()

# make it suitable for caseless comparison

str = str.casefold()

# reverse the string

rev_str = reversed(str)

# check if the string is equal to its reverse

if list(str) == list(rev_str):

print("The string is a palindrome.")

else:

print("The string is not a palindrome.")

You might also like