Naincy Mod 1 Python
Naincy Mod 1 Python
LAB 1
Output :-
Hello Python
Explanation :-
of",a,"&",b,"is =",c)
Output :-
:-
• The first number is accepted from the user and stored in variable
‘a’.
• The second number is accepted from the user and stored in
variable ‘b’.
• The sum of both the numbers ‘a’ & ‘b’ is calculated & stored in
variable ‘c’.
• The value of ‘c’ is then displayed.
Output :-
:-
• The larger number is accepted from the user & stored in variable
‘a’.
• The smaller number is accepted from the user & stored in variable
‘b’.
• The smaller number is subtracted from the larger one & the
difference is stored in variable ‘c’.
• The value of the variable ‘c’ is then displayed.
Output :-
Product of 5 & 4 is = 20
Explanation :-
• The first number is accepted from the user & stored in variable ‘a’.
• The second number is accepted from the user & stored in variable
‘b’.
• Both the numbers are multiplied & the product is stored in variable
‘c’.
• The value of the variable ‘c’ is then displayed.
Output:-
Explanation :-
• The larger number is accepted from the user & stored in variable
‘a’.
• The smaller number is accepted from the user & stored in variable
‘b’.
• Firstly, normal division is performed by using the / operator and
the result obtained is stored in the variable ‘c’.
• Then, floor division is performed by using the // operator & the
quotient obtained is stored in the variable ‘d’.
• The values of both division & floor division are displayed
thereafter.
:-
a=int(input("Enter the 1st side of the triangle :- "))
=",area) Output :-
Enter the 1st side of the triangle :- 10
:-
• The length of the first side of the triangle is accepted from the user
& stored in ‘a’.
• The length of the second side of the triangle is accepted from the
user & stored in ‘b’.
• The length of the third side of the triangle is accepted from the
user
& stored in ‘c’.
• All the lengths are added and the result is halved. This is stored in
a variable ‘s’ which is known as semi-perimeter.
• Then to calculate the area, the value of ‘s’ is multiplied with the
difference which is obtained when the lengths of all the sides are
subtracted from the semi-perimeter. The square root of the above
result is the area of the triangle.
• The area of the triangle is then displayed.
Output :-
Enter a number :- 5
Prime Number
Enter a number :- 9
Explanation :-
:-
a=int(input("Enter the value of A :- ")) b=int(input("Enter
the value of B :- ")) print("Before Swapping :-") print("A
=",a) print("B =",b) t=a a=b b=t print("After
Swapping :-") print("A =",a) print("B
=",b)
Output :-
Before Swapping :-
A=6
B=7
After Swapping :-
A=7
B=6
Explanation :-
• First, the value of A & after that the value of B is accepted from
the user & stored in their respective variables.
• Before Swapping, the values of A & B are displayed.
• The value of ‘a’ is stored in a variable ‘t’.
• Then, the value of ‘b’ is assigned in variable ‘a’. • After that, the
current value of ‘t’ is assigned in variable ‘b’.
• Now, the numbers are swapped. The values of both A & B are
displayed again.
:-
a=int(input("Enter a year :- "))
if(a%100==0): if(a%400==0):
print("Leap Year")
else: print("Not a
Leap Year") else: if(a%4==0):
print("Leap Year")
else: print("Not a Leap
Year")
Output :-
Leap Year
Explanation :-
Number") Output
:-
Enter a number :- 5
Odd Number
Enter a number :- 6
Even Number
Explanation :-