0% found this document useful (0 votes)
12 views16 pages

AI Journal Viraj Bhardwaj

The document contains a list of Python programs that cover various basic functionalities such as a simple calculator, area calculations for different shapes, checking leap years, list manipulations, Fibonacci series, factorial calculation, string reversal, multiplication tables, star patterns, number patterns, prime checking, palindrome checking, and summing digits of a number. Each program includes code snippets and expected outputs. The programs are designed for educational purposes, likely for a class project.

Uploaded by

virajstudies
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)
12 views16 pages

AI Journal Viraj Bhardwaj

The document contains a list of Python programs that cover various basic functionalities such as a simple calculator, area calculations for different shapes, checking leap years, list manipulations, Fibonacci series, factorial calculation, string reversal, multiplication tables, star patterns, number patterns, prime checking, palindrome checking, and summing digits of a number. Each program includes code snippets and expected outputs. The programs are designed for educational purposes, likely for a class project.

Uploaded by

virajstudies
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
You are on page 1/ 16

Index

1.Program To Stimulate Simple calculator


2.Print Area of square,circle and rectangle
3.Check if leap year or not using input from user
4.Python Programs for list manipulation
5.Print fiboancci series in a certain range
6.Print factorial of a number using for loop
7.Program to reverse a string
8.print multiplication table of any number
9.Print star pattern using nested loop
10.Print number pattern using nested loop
11.Program to check if number prime or not
12.Program to check if number palindrome or not
13.Calculate area of different shapes using while loop
14.program to find sum of digits of a number
1.Program To Stimulate Simple calculator

Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Python program to simulate simple calculator
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
op = int(input("Select operations 1- Addition, 2- Subtraction, 3-
Multiplication, 4- Division:"))
if op==1:
print(num1, "+", num2, "=",num1+num2)
elif op==2:
print(num1, "-", num2, "=",num1-num2)
elif op==3:
print(num1, "*", num2, "=",num1*num2)
elif op==4:
print(num1, "/", num2, "=",num1/num2)
else:
print("Invalid input")

OutPut:

2. Program To Stimulate Simple calculator


Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
op = int(input("Choose option to calculate area, perimeter of 1- Circle
2- Square 3- Rectangle: "))
if op == 1:
# To calculate area, perimeter of circle
r = float(input("Enter radius: "))
a = 3.14 * r * r
p = 2 * 3.14 * r
print("Area of circle is =", a)
print("Perimeter of circle is =", p)

elif op == 2:
# To calculate area of Square
r = float(input("Enter side: "))
a = r * r
print("Area of square is =", a)

elif op == 3:
# To calculate area of rectangle
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
a = l * b
print("Area of rectangle is =", a)

else:
print("Invalid input")

Output:

3. Check if leap year or not

Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
a = int(input("Enter any Year: "))

if a > 10000 or a < 0:


print("Invalid Year; Enter a valid year")
elif a % 4 == 0:
print("It is a leap year")
else:
print("It is not a leap year")

OutPut:
4. List Manipulation
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")

list1 = [] # create empty list

n = int(input("How many numbers you want to enter: ")) # enter length


of list

for i in range(0, n):


num = int(input("Enter number: "))
list1.append(num) # append elements to the list
print("Created list is:", list1)

while True:
print("\nList Manipulation")
print("1. Sort")
print("2. Pop a number from the list")
print("3. Reverse the list")
print("4. Remove a number")
print("5. Exit")

ch = int(input("Enter your choice: "))


if ch == 1:
print("List before sort:", list1)
list1.sort()
print("List after sort:", list1)
elif ch == 2:
pop_no = list1.pop()
print("Popped number:", pop_no)
elif ch == 3:
print("List before reverse:", list1)
list1.reverse()
print("Reversed list:", list1)
elif ch == 4:
print("List before removing a number:", list1)
n = int(input("Enter number to be removed: "))
list1.remove(n)
print("List after removing a number

OutPut:
5. Print Fibboaccci series using for loop
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Program to display Fibonacci series upto nth term
num = int(input("Enter a number of terms to print in Fibonacci series:
"))
n1 = 0
n2 = 1
print(n1)
print(n2)

for i in range(1, num - 1):


n3 = n1 + n2
print(n3)
n1 = n2
n2 = n3

OutPut:

6. Factorial Of a Number

Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Python program to find the factorial of a number provided by the user.
num = int(input("Enter a number: "))
fact = 1
for i in range(1,num + 1):
fact = fact*i
print("The factorial of", num ,"is", fact)

OutPut:

7. Reverse a string

Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Printing reverse of String

txt = input("Enter String: ")


a = txt[::-1]
print("Reversed string is:")
print(a)
Output:

8. Print Multiplication table


Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Printing multiplication table for a given number

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


r = int(input("Enter range till which to print: "))

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


print(n, ' * ', i, ' = ', n * i)

Output:
9. Print star Pattern
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")

# Print star pattern


rows = 6

# Outer loop
for i in range(rows):
# Nested loop
for j in range(i):
# Display asterisk (*)
print("*", end=' ')
# Move to the next line after each row
print('')

Output:
10. Print Number Pattern
Code:
print("Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Print number pyramid pattern
rows = 6

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


# Print spaces for left alignment
print(' ' * (rows - i), end='')

# Print numbers in increasing order


for j in range(1, i + 1):
print(j, end=' ')

# Move to the next line after each row


print('')

Output:
11. Number Prime Or Not
COde:
print("Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# Python program to check if given number is prime or not
num = int(input("Enter a number: "))
for i in range(2, num):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")

Output:
12. Check if Palidrome or not
Code:
print("Name:Viraj Bhardwaj")
print("Class and sec:10-F")
number = int(input("Enter the integer number: "))
temp = number
rev = 0

while number > 0:


remainder = number % 10
rev = (rev * 10) + remainder
number = number // 10

print("The reverse number is:", rev)

if temp == rev:
print("The number is palindrome")
else:
print("The number is not a palindrome")

Output:
13. Calculate area of different shapes
Output:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
while True:
print("\nCALCULATE AREA")
print("1. Circle")
print("2. Rectangle")
print("3. Square")
print("4. Exit")

choice = int(input("Enter the Choice:"))

if choice == 1:
radius = int(input("Enter Radius of Circle:"))
area = 3.14 * radius * radius
print("Area of Circle:", area)

elif choice == 2:
height = int(input("Enter Height of Rectangle:"))
width = int(input("Enter Width of Rectangle:"))
area = height * width
print("Area of Rectangle:", area)

elif choice == 3:
side = int(input("Enter Side of Square:"))
area = side * side
print("Area of Square:", area)

elif choice == 4:
break
else:
print("Oops! Incorrect Choice.")

Output:
14. Find sum of digits of a number
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
n = int(input("Enter number: "))
sum = 0

while n != 0:
sum = sum + (n % 10)
n = n // 10

print("Sum of the digits of the entered number is:", sum)

Output:

You might also like