PRIP 1.2 Sumita Arora Solutions | Class 12 Computer Science

Here are PRIP 1.2 Sumita Arora Solutions for class 12 Computer Science. To view chapter 1 lecture videos, visit here.

To view Sumita Arora solutions for all chapters, visit here.

Q.1: In each of the following Python expressions or statements, indicate what data type belongs in the indicated place by choosing one of these data types:
int, float, bool, str, list

Expression

  Correct Datatype (Answers)

(a)    s = _______ + 17

int

(b)   T = _______+’pie’

str

(c)    x[______] = ‘catfood’

int

(d)   ______.sort()

list

(e)   if ______ :

bool

Q.2: What does Python print as it executes the following sequence of statements?

Expression

Correct Datatype (Answers)

(a)    print((10+3)*2)

26

(b)   print(11/2)

5.5

(c)    x = 25
        print(x*2 == 50)

True

(d)   print(x/2 >= 50)

False

(e)   a = ‘Honda’
        b = ‘Audi’
        print(a+b)

HondaAudi

(f)    c = len(a) + len(b)
        print(c)

9

(g)    print(a)

Honda

(h)   print(a[1])

o

Q.3: What would be the output of following code?
a = 9000            #initializes and assigns value to variable
print("Now it's a", type(a))
a = float(a)
print("Now it's a", type(a))
a = str(a)
print("Now it's a", type(a))

Answer:

code:
a = 9000            #initializes and assigns value to variable
print("Now it's a", type(a))
a = float(a)
print("Now it's a", type(a))
a = str(a)
print("Now it's a", type(a))

output:

#type function returns the type of variable passed as parameter
Now it's a <class 'int'>
Now it's a <class 'float'>
Now it's a <class 'str'>

Q.4: What would be the output of following code? Support your answer with reason.
               x = 4
               y = 8
               z = x/y*y
               print(z)

Answer:

x = 4
y = 8
z = x/y*y
print(z)

Explanation:

x/y = 4/8 = 0.5

0.5*y = 0.5*8 = 4.0

Q.5: Which of the following statements would yield 2? Assume that math module is imported. Recall that math.fabs() gives you absolute value of its arguments.
a. print(5/2)
b. print(5.0//2)
c. print((int)(5.0/2))
d. print(math.fabs(-5.0/2))
e. print(math.fabs(-5.0//2 ))
f. print(math.fabs(-3//2))
g. print(-5/2)
h. print(-5/2)

i. print(-5//2)
j. print(-5.0//2)

Answer:

print((int)(5.0/2))
gives output 2

Note:
maths.fabs(value)
Parameter:
value: variable / number / expression
Returns: the absolute value of the Parameter.
5/2 gives 2.5
5//2 gives 2.0
// is for floor division

Q.6: Which of the following statements would yield 2.0? Assume that math module is imported. Recall that math.fabs() gives you absolute value of its arguments.
a. print(5/2)
b. print(5.0//2)
c. print((int)(5.0/2))
d. print(math.fabs(-5.0/2))
e. print(math.fabs(-5.0//2 ))
f. print(math.fabs(-3//2))
g. print(-5/2)
h. print(-5/2)

i. print(-5//2)
j. print(-5.0//2)

Answer:

print(5.0//2)
print(math.fabs(-3//2))
gives output 2.0

Q.7: What would be the output produced by the print statements given in previous questions?

Answer:

Code:
print(5/2)
print(5.0//2)
print((int)(5.0/2))
print(math.fabs(-5.0/2))
print(math.fabs(-5.0//2 ))
print(math.fabs(-3//2))
print(-5/2)
print(-5/2)
print(-5//2)
print(-5.0//2)

Output:
2.5
2.0
2
2.5
3.0
2.0
-2.5
-2.5
-3
-3.0
Q.8: What would be the output of following?
(a)  print(type([1,2]))
(b) print(type(1,2))
(c)  print(type((1,2)))
(d) print(type(1/2))
(e)  print(type([1/2]))
(f)   print(type( (1/2)))
(g)  print(type( (1/2, )))

Answer:

Code:
print(type([1,2]))
print(type(1,2))       
print(type((1,2)))   
print(type(1/2))     
print(type([1/2]))   
print(type( (1/2)))  
print(type( (1/2, )))
               
Output:
<class 'list'>
TypeError: type() takes 1 or 3 arguments
<class 'tuple'>
<class 'float'>
<class 'list'>
<class 'float'>
<class 'tuple'>
   
Note:
type() function takes 1 or 3 arguments
1. type([1,2])   [1,2] is one argument which is list
2. type(name,tuple,dict)
Q.9: What would be the output of following?
x = True
y = False
z = False
print(x or y and z)

Answer:

or a b    a|b
   0 0     0
   0 1     1
   1 0     1
   1 1     1
 
and a b    a&b
    0 0     0
    0 1     0
    1 0     0
    1 1     1
= x or y and z
= True or False and False
= True or False
= True

Note:
According to the relative precedence levels of operators in programming
& is at higher priority than | that is why y and z executed first
Q.10: Given the following Boolean variables, what would be the output of the following statements?
x = True
y = False
z = False
(a)  print(not x or y)
(b) print(not x or not y and z)
(c)  print(not x or y or not y and x)
(d) print(‘ant’ < ‘amoeba’)

Answer:

a)  print(not x or y)
= not True or Flase
= False or Flase
= False

b)  print(not x or not y and z)
= not True or not False and False
= False or True and False
= False or False
= False
 
c)  print(not x or y or not y and x)
= not True or False or not False and True
= False or Flase or True and True
= False or Flase or True
= Flase or True = True
 
d)  print('ant' < 'amoeba')

a = a
but n>m hence 'ant' < 'amoeba'
i.e. 'ant' < 'amoeba' = Flase
 
Note:
While comparing strings with operators <=, >=, <, >
The comparison is done character by character.
Q.11: Write a program to find the side of a square whose perimeter you read from user.

Answer:

Code:
perimeter = int(input("Enter perimeter of square : "))
square_side = perimeter/4
print("Side of square is {}".format(square_side))

Output:
Enter perimeter of square: 20
Side of square is 5.0

Q.12: Write a program to calculate the distance of 1056 feet in terms of yard and miles. Given fixed values are 1 mile = 1760 yards and
1 yard = 3 feet

Answer:

'''
given 1056 feet
1 mile = 1760 yards
1 yard = 3 feet
'''
Code:
feet = 1056
yards = feet/3
mile = yards/1760
print("feet = {}".format(feet))
print("yards = {}".format(yards))
print("mile = {}".format(mile)

Output:
feet = 1056
yards = 352.0
mile = 0.2

Q.13: An athlete is taking rounds of a triangular park with sides as 30m , 25m and 35m. The athlete has run 560m till now. Write a program to print how many rounds of park the athlete has complete.

Answer:

"""
Given:
sides
a = 30m
b = 25m
c = 35m
approach: 
first find perimeter of triangle
dividing 560m by perimeter will give number of rounds
"""

Code:

a = 30
b = 25
c = 35
distance = 560
perimeter = a + b + c
rounds = distance / perimeter
print("Total rounds of ground : {:.2f} m ".format(rounds))
 

Output:

Total rounds of ground : 6.22 m
Q.14 Write a Python program that calculates and print on the screen the number of seconds in a year.

Answer:

Code:
days = 365
hrs = 24
minutes = 60
seconds = 60
total_seconds = days * hrs * minutes * seconds
print("Total seconds in a year {}.".format(total_seconds))

Output:
Total seconds in a year 31536000.

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
amiesite
amiesite
3 years ago

very helpfull
thanku

You cannot copy content of this page