0% found this document useful (0 votes)
26 views

Python Funda Practice Questions

HI

Uploaded by

vinu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Python Funda Practice Questions

HI

Uploaded by

vinu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 7 – Python Fundamentals

ANSWER THE FOLLOWING (10x2=20 Marks)

1. From the following, find out which assignment statement will produce an error. State reason(s)
too. (2)
(a) x = 55
(b) y = 037
(c) z = 0o98
(d) 56thnumber = 3300
(e) length = 450.17
(f) !Taylor = 'Instant'
(g) this variable = 87.E02
(h) float = .17E - 03
(i) FLOAT = 0.17E – 03

ANSWER

(c) It is invalid octal integer literals.


(d) Invalid identifiers because digits cannot be used as first character of identifier.
(f) Invalid identifiers because specific character cannot be used for identifier.
(g) Because in identifiers cannot accept space (white space).
(h) Keywords cannot be used as identifiers.
(i) invalid syntax of exponent form.

2. Find out the error(s) in following code fragments:

ANSWER
(i) temperature = 90
print (temperature)
(ii) a = 30
b=a+b
print (a, b)

(iii) a, b, c = 2, 8, 9
print (a, b, c)
c, b, a = a, b, c
print (a, b, c)
(iv) X = 24
X=4
(v) ‘X’ is not defined
(vi) “else” Keywords cannot be used as identifiers
3. What will be the output produced by following code fragment (s)? (3)

ANSWER
(i) 15
13 22
(ii) 235
10 3 30
(iii) Side 7 - 7 49

4. What is the problem with the following fragments? (3)

ANSWER
i)Indentation is present in print statement.
ii) String and number cannot add.
iii) String and numbers cannot divide.

5. Consider the following code: (1)


name = input('What is your name? ')
print ('Hi', name, ',')
print ('How are you doing? ')
was intended to print output as
Hi <name>, How are you doing?
But it is printing the output as:
Hi <name>,
How are you doing?
What could be the problem? Can you suggest the solution for the same?
ANSWER
Problem is that second print statement print the code in newline
Correct way:-
name = input('What is your name? ')
print ('Hi', name, ',','How are you doing? ')

6. What will be returned by Python as result of following statements?

(a) >>> type(0) (b) >>>type(int(0)) (c) >>>.type(int('0')) (d) >>> type('0')
(e) >>>type(1.0) (f) >>>type(int(1.0)) (g) >>>type(float(0)) (h) >>>type(float(1.0))
(i) >>>type(3/2)
ANSWER

(a) <class 'int'> (b)<class 'int'> (c) Error (d) <class 'str'>
(e) <class 'float'> (f)<class 'int'> (g) <class 'float'> (h) <class 'float'> (i) <class 'float'>

7. Correct the following program so that it displays 33 when 30 is input. (1)

val = input("Enter a value")


nval = val + 30
print (nval)
ANSWER

val = int(input("Enter a value"))


nval = val + 3
print (nval)

8. Predict the output (2)

a, b, c = 10, 20, 30
p, q, r = c-5, a +3, b - 4
print ('a, b, c :', a, b, c, end = '')
print ('p, q, r : ', p, q, r)
ANSWER
a, b, c : 10 20 30 p, q, r : 25 13 16

9. Write a program to obtain principal amount , rate of interest and time from user and compute simple
interest. (2)

principal = int(input("Enter principal amount = "))


rate = int(input("Enter rate = "))
time = int(input("Enter time = "))
si = principal * rate * time / 100
print("Simple interest = ",si)

10. Write a program to input the radius of a sphere and calculate its volume. (2)

(V=4/3 πr3)
rad = int (input("Enter the radius :-"))
volume = (4/3) * 3.14 * rad ** 3
print ("Volume = ", volume)

You might also like