You are on page 1of 3

7: PYTHON FUNDAMENTALS

Chapter 197

5.
5. Write the output of the following
(a) num1 = 4
(b) num1, num2 = 2, 6
num2 =
num1 +11 num1, num2 = num2, num1 +2
num1 = 2
print(num1, num2)
print(num1, num2)
(c)
(C) num1, num2 2, 3 =

num3, num2 = num1, num3 +1


print(num1, num2, num3)
Ans.(a) 25 (b) 6 4 (b) Error: num3 not defined.
12. Write a progran1 to calculate in how many days a work will be completed by three persons A, B and c
together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to calculate the
number of days if they work together is xyz/ (xy+ yz + xz) days where x, y, and z are given as input to the
progran.

Ans.
X int(input("Enter value of x : "))
y int(input("Enter value of y: "))
z int(input("Enter value of z : "))
print("Individually, A, B and C take days respectively as " , x, y, z)
days (x*y*z)/(x*y + y*z +x*z)
print("Together A, B and C take days as:", days)

Sample run:
Enter value of x : 10
Enter value of y : 15
Enter value of z : 12

Individually, A, B and C take days respectively ac 10 1 112


TOgether A. B and C take days as 4.0
"XY XY.J?
\a, "a","Reemal's", " ' , "it's", YZ"
lutin
\a i e is l aa there in l character (escape sequence)
and it is a
string literal enclosedi
ingle q1tes

"\a" I character enclosed in double quotes.


ie
i l as thero is
bcaue it is string having 7 characters
enclosed in double quotes. (
Reemal'" ie i7 a

apostrophe and is considered a single character.)


a p e equene for

Itis character constant and is containing just one character


"..
'" ieinI a

"it'" i z e in P'ython allows single quote without escape sequence


in double quoted strin
a

and a double quote without escape sequence in a single quoted string e.g., 'no."ltag'.

"xy
y" Size is 4. It is a nulti-line string create with \ in the basic string.

"Xy.I
multi-line EOL (J) character is also counted in size-
y" Sie is 5. Triple quoted string,

o m a y uu's f strings urr supported in Python ?


Solution. I'ython allows tww string types:
() inghe lie Stings Strings that are terminated in single line
() Mulln lne Strings Strings storing multiple lines of text.
/ritethe following real constants in exponent form: 17.251, 151.02, 0.00031, 0452

Solution.
)17.251 =0.17251x10 =
0.17251E02 (ii) 151.02 -0.15102 10 0.15102E0
(ii) 0.00031 =0.31x 10 =
0.31E-3 (io) 0.452 =0.0452 10 0.0452E0I
What is None literal in Python ?
Solution. Python has one special literal called None.

The None literal is used to indicate something yet been created


that has not in simple words,
absence of value. It is also used to indicate the end of lists in Python.

0. Identify the types of following literals ?


23.789 23789 True True' "True"

False "False' OXFACE O0213 0o789


Solution.
23.789 Floating point 23789 integer
True Boolean True String
False Boolean
True" String
String OXFACE Integer (Hexadecimal)
"False'"
O0213 Integer(Octal)
Invalid token ( beginning with 0 means it is octal number but digits
Oo789
8 and 9 are invalid digits in octal numbers)

None None
and a statement in Python ?
11. What is the difference between an expression
Solution.

Expression Statement
Programming instruction as
per Python syntax
Legal combination of symbols
Does something
Represents something
Python executesit
Python evaluates it
Need not result in a value
End result is a value
Examples: print ("Hello")
Example: 2.3
(3+5)/ 4 i fa>3

You might also like