AI Journal Viraj Bhardwaj
AI Journal Viraj Bhardwaj
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:
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:
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
a = int(input("Enter any Year: "))
OutPut:
4. List Manipulation
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
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")
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)
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
Output:
9. Print star Pattern
Code:
print( "Name:Viraj Bhardwaj")
print("Class and sec:10-F")
# 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
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
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")
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
Output: