0% found this document useful (0 votes)
4 views8 pages

Journal N Docs

The document contains a series of Python programs created by Viraj Bhardwaj for a class project, including a simple calculator, area and perimeter calculations for shapes, leap year checker, list manipulation, Fibonacci series generator, factorial calculation, and string reversal. Each program prompts the user for input and performs the specified calculations or manipulations. The document showcases basic programming concepts and operations in Python.

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)
4 views8 pages

Journal N Docs

The document contains a series of Python programs created by Viraj Bhardwaj for a class project, including a simple calculator, area and perimeter calculations for shapes, leap year checker, list manipulation, Fibonacci series generator, factorial calculation, and string reversal. Each program prompts the user for input and performs the specified calculations or manipulations. The document showcases basic programming concepts and operations in Python.

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/ 8

Index:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

1.Program to Stimulate a simple calculator


Code:
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
print("")
print("1:add")
print("2:subtract")
print("3:multiply")
print("4:divide")
print("5:floor divide")
print("6:modulous")
print("7:exponent")

choice = int(input("Choose :"))


if choice == 1:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1+num2)
elif choice == 2:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1-num2)
elif choice == 3:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1*num2)
elif choice == 4:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1/num2)
elif choice == 5:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1//num2)
elif choice == 6:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1%num2)
elif choice == 7:
num1 = int(input("Enter num 1 :"))
num2 = int(input("Enter num 2 :"))
print("Your answer is =" ,num1**num2)
else:
print("dhang ka numbar dall nalle!")

Output:

2.Area and Perimeter of shapes


Code.
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
#Area or perimeter of circle square or rectangel
def square(type_need):
s=float(input("Enter side"))
if type_need == 1:
print("the area is =",s*s)
elif type_need == 2:
print("the perimeter is =",4*s)

def rectangle(type_need):
le=float(input("Enter lenth"))
b=float(input("Enter bredth"))
if type_need == 1:
print("the area is =",le*b)
elif type_need == 2:
print("the perimeter is =",2*(le+b))

def circle(type_need):
r=float(input("Enter radius"))
if type_need == 1:
print("the area is =",(22/7)*r*r)
elif type_need == 2:
print("the perimeter is =",2*(22/7)*r)

f=int(input("Enter 1 for circle,2 for square, 3 for rectangle:"))


c = int(input("Enter 1 for area or 2 for perimeter: "))

if f==1:
if c == 1:
circle(1)
elif c == 2:
circle(2)
elif f ==2:
if c ==1:
square(1)
elif c == 2:
square(2)
elif f==3:
if c == 1:
rectangle(1)
elif c == 2:
rectangle(2)
else:
print("Pls enter valid numbers")

Output:

3.Check If Leap Year


Code:
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
print("")
#Leap Year
a=int(input("Enter year"))
if a%4==0 and a <=50000 and a >= 0:
print("Leap Year")
elif a <=0 or a>=100000 :
print("enter valid year")
else:
print("no leapm year")

Output:
4.List Manipulation(In interactive mode)
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
print("")
>>> list1=[1,2,4,5]
>>> list1.insert(3,2)
>>> print(list1)
[1, 2, 4, 2, 5]
>>> list[6,7,8]
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
list[6,7,8]
TypeError: 'type' object is not subscriptable
>>> list2= [6,7,8]
>>> list1.extend(list2)
>>> print(list1)
[1, 2, 4, 2, 5, 6, 7, 8]
>>> list1.pop(1)
2
>>> print(list1)
[1, 4, 2, 5, 6, 7, 8]
>>> l1=[1,2,3]
>>> l2=[4,5,6]
>>> l1==l2
False
>>> l1+l2
[1, 2, 3, 4, 5, 6]
>>> l1*l2
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
l1*l2
TypeError: can't multiply sequence by non-int of type 'list'
>>> is 5 in l1
SyntaxError: invalid syntax
>>> 5 in l1
False
>>> 5 in l2
True
>>> l1 is l2
False
>>> a=10
>>> type(a)
<class 'int'>
>>> b=2.5
>>> type(b)
<class 'float'>
>>> c="hello"
>>> type(c)
<class 'str'>

5.Fibboancci Series:

Code:
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
print("")
num = int(input("Enter a limit"))
a=0
b=1

for i in range(1,num+1):
if a<=num:
c=a+b
print(a)
a=b
b=c
Output:

6. Factorial:
Code:
print("Name :Viraj Bhardwaj")
print("class and sec : 10F")
print("")
a=int(input("Enter a number:"))
b=1
for i in range(1,a+1):
b*=i
print(b)

Output:

7. Reverse a String:
Code:
print("Viraj Bhardwaj")
print("10.F, 36")
print("Reverse a string")

a = input("Enter the string to be reversed")


print(a[::-1])
Output:

You might also like