Python Assignment 1
Ans 1.
a=int(input('Enter the first no.'))
b=int(input('Enter the second no.'))
c=a+b
print('The sum of the given nos. = ',c)
d=a-b
print('The difference of the given nos. = ',d)
e=a*b
print('The product of the given nos. = ',e)
f=a/b
print('The quotient when the given nos. are divided = ',f)
g=a%b
print('The remainder when the given nos. are divided = ',g)
h=a//b
print('The integer quotient when the given nos. are divided = ',h)
OUTPUT
Enter the first no. 5
Enter the second no.6
The sum of the given nos. = 11
The difference of the given nos. = -1
The product of the given nos. = 30
The quotient when the given nos. are divided = 0.8333333333333334
The remainder when the given nos. are divided = 5
The integer quotient when the given nos. are divided = 0
Ans 2.
p = float(input("Enter the principal amount: "))
r = float(input("Enter the rate of interest (in %): "))
t = float(input("Enter the time (in years): "))
s=(p*r*t)/100
print('Simple Interest = ',s)
OUTPUT
Enter the principal amount: 1000
Enter the rate of interest (in %): 5
Enter the time (in years): 2
Simple Interest = 100.0
Ans 3.
l=float(input("Enter the length: "))
b=float(input("Enter the breadth: "))
area=l*b
print('The area of the rectangle = ',area)
OUTPUT
Enter the length: 10
Enter the breadth: 4
The area of the rectangle = 40.0
Ans 4.
a=float(input("Enter the first side: "))
b=float(input("Enter the second side: "))
c=float(input("Enter the third side: "))
s=(a+b+c)/2
a=(s*(s-a)*(s-b)*(s-c))**1/2
print('The area of the triangle = ',a)
OUTPUT
Enter the first side: 5
Enter the second side: 7
Enter the third side: 10
The area of the triangle = 132.0
Ans 5.
a=float(input("Enter the temperature in Fahrenheit: "))
b=(a-32)*5/9
print('The temperature in Celcius = ',b)
OUTPUT
Enter the temperature in Fahrenheit: 98
The temperature in Celcius = 36.666666666666664
Ans 6.
a=int(input('Enter the time (in minutes): '))
h=a//60
m=a%60
print('Time: ',h,'hours and',m,'minutes')
OUTPUT
Enter the time (in minutes): 90
Time: 1 hours and 30 minutes
Ans 7.
a=float(input('Enter the height (in inches): '))
f=a//12
i=a%12
print('Height: ',f, 'feet and',i, 'inches')
OUTPUT
Enter the height (in inches): 70
Height: 5.0 feet and 10.0 inches
Ans 8.
a=int(input("Enter a no."))
b=int(input("Enter a no."))
print(id(a))
print(id(b))
c=a
a=b
b=c
print(id(a))
print(id(b))
OUTPUT
Enter a no.7
Enter a no.8
140729610095224
140729610095256
140729610095256
140729610095224
Ans 9.
a=int(input('Enter a no.'))
a=b=c
print(id(a))
print(id(b))
print(id(c))
OUTPUT
Enter a no.10
140729610095224
140729610095224
140729610095224
Ans 10.
a=input('Write any sentence: ')
print(a,'#')
OUTPUT
Write any sentence: You are pretty
You are pretty #
Ans 11.
a=int(input('Enter mathematics mark: '))
b=int(input('Enter english mark: '))
c=int(input('Enter science mark: '))
d=int(input('Enter social studies mark: '))
e=int(input('Enter sanskrit mark: '))
print('Mathematics = ',a,' English = ',b,' Science = ',c,' Social Studies = ',d,' Sanskrit = ',e)
OUTPUT
Enter mathematics mark: 99
Enter english mark: 98
Enter science mark: 97
Enter social studies mark: 100
Enter sanskrit mark: 98
Mathematics = 99 English = 98 Science = 97 Social Studies = 100 Sanskrit = 98
Ans 12.
x="""a)"The professor said,"Please don't sleep in the class.'" """
y="""#b)"Opportunities don't happen. You create them." Try not to become a person of
"success" but try to become a person of "value" """
print(x)
print(y)
OUTPUT
a)"The professor said,"Please don't sleep in the class.'"
#b)"Opportunities don't happen. You create them." Try not to become a person of "success"
but try to become a person of "value"
Ans 13.
a=input('Enter you name: ')
b=int(input('Enter no. of times you want the name to repeat: '))
print(a*b)
OUTPUT
Enter you name: Vani
Enter no. of times you want the name to repeat: 6
VaniVaniVaniVaniVaniVani
Ans 14.
a=input('Enter you first subject: ')
b=input('Enter you second subject: ')
c=input('Enter you third subject: ')
d=input('Enter you fourth subject: ')
e=input('Enter you fifth subject: ')
print(a,'*',b,'*',c,'*',d,'*',e)
OUTPUT
Enter you first subject: English
Enter you second subject: Maths
Enter you third subject: Physics
Enter you fourth subject: Chemistry
Enter you fifth subject: Computer Science
English * Maths * Physics * Chemistry * Computer Science