Python Work Sheet
I never dreamt of success. I worked for it………. Dr.VVR
Task-1: Execute the below code and write the output.
Code Error Name Error Description
prnt (“Hello World”)
Print (“Hello World”)
print (Hello World)
print (“Hello World”
Task-2: Write the code for below requirements.
Requirement Code /Output
Display 1947 August Month
Calendar
Find the value of sqrt (-36)
Find the value of factorial of 45
Display 1992 Year Calendar
LITAM, PYTHON WORK SHEET, TPO 1
Generate 4 digits OTP
Generate 6 digits OTP
Write output for below code
print(0b1111)
print(0o1256)
print(0x1786)
print(0b112)
print(0o1897)
print(0xABFG)
print(0xabef)
Task-3: Draw a diagram to show how the values get stored in the main
memory of the computer.
LITAM, PYTHON WORK SHEET, TPO 2
Task-4: Exercise on rules of the variable name.
Variable Name Valid/Invalid
sal=56
_sal=67
_sal=67
sal$=67
__sal=56
__=56
123=56
emp sal=45
emp-sal=56
emp_sal=56
emp$sal=56
emp1sal=56
false=67
while1=56
_while=67
for=56
for2=67
False=67
while=56
age=99 AGE=98 Age=97 aGe=96
print (age, AGE,Age,aGe)
Code Output
print (type (10))
print(type(0B10011))
print(type(0O1467))
print(type(0xDEAR))
print(type(0xBEE))
LITAM, PYTHON WORK SHEET, TPO 3
Code Output
print (type (17.9))
print(type(6e-2))
a=7e-5
print(a)
a=0.0000000000000000000000078
print(a)
a=0b1111.0b1010
print(a)
a=0o1267.0o3456
print(a)
a=0xBEE.0x34
print(a)
Code Output
print (type (True))
print (type (False))
print(type(false))
print(type(true))
print (True/True)
print (True/False)
print (False/False)
print (False/True)
print (True+3*True-6*False)
print (True-2+False)
print(0b1111+True)
print(0xF-True)
Code Output
print(type(3+4j))
print(type(5-4j))
print(type(-10-6j))
print(type(4j))
LITAM, PYTHON WORK SHEET, TPO 4
print(type(-8j))
a=-10j
print(a)
a=-10j
print(a.real)
print(a.imag)
a=-8-
10j
print(a.real)
print(a.imag)
a=-8
print(a.real)
print(a.imag)
a=4+5j
print (a. imaginary)
a=10+13j
b=-7-9j
c=a*b
print(c)
print(2+14j+5+24j)
Task-5: s=’PYTHON PROGRAMMING IS FUN’. Draw the memory
management diagram for the given strobj.
Task-6: ss = "Sammy Shark!"
ss[0] ss[11] ss[5] ss[12] ss[-12] ss[-1] ss[-7] ss[-13] ss[-4] ss[-9]
LITAM, PYTHON WORK SHEET, TPO 5
ss[0:12]
ss[1:6]
ss[2:9]
ss[4:10]
ss[5:11]
ss[11:1100]
ss[5:6]
ss[7:6]
ss[-12:-1]
ss[-9:-2]
ss[-11:-5]
ss[-10:-2]
ss[-9:-4]
ss[-6:-9]
ss[-1000:-7]
ss[:-7]
ss[:-1000]
ss[:0]
ss[:-1]
ss[:-8]
ss[:9]
ss[:3]
ss[:11]
ss[1:]
ss[7:]
ss[7000:]
ss[-1:]
ss[-11:]
LITAM, PYTHON WORK SHEET, TPO 6
ss[-9:]
ss[:]
ss[-9:8]
ss[-11:11]
ss[1:-4]
ss[8:-2]
ss[-9:12]
ss[2:-9]
ss[-11:2]
ss[4:-11]
ss[4:-11]
ss[-8:1]
ss[::-1]
ss[::-2]
ss[::-6]
ss[::-600]
ss[::5]
ss[::1]
ss[::700]
ss[0:12:1]
ss[1:11:2]
ss[1:11:-2]
ss[3:11:5]
ss[2:11:7]
ss[-11:-1:-1]
ss[-1:6:-1]
ss[-3:3:-1]
ss[1:-7:1]
LITAM, PYTHON WORK SHEET, TPO 7
ss[-11:2:1]
ss[-15:-25:-1]
ss[-1000::-1]
ss[:-1:-1]
ss[:0:1]
ss[:-1:-6]
ss[:0:7]
ss[:0:3]
ss[:-1:-2]
ss[:-1:-3]
What is the difference between Mutable & Immutable objects.
Task-8:
Code Output
a=10
print(a,id(a))
a=a+1
print(a,id(a))
a=4.5
print(a,id(a))
a=a+1
print(a,id(a))
LITAM, PYTHON WORK SHEET, TPO 8
a=3+4j
print(a,id(a))
a=a+1
print(a,id(a))
a=True
print(a,id(a))
a=a+1
print(a,id(a))
s='PYTHON'
s[0]
s[0]="J"
l=[10,20,30,40,50]
l[0]
print(l, id(l))
l[0]=100
print(l, id(l))
Task-9
Code Output Code Output
print(int(12.34)) print(int(2+3j))
print(int(0.45)) print(int(-5j))
print(int(True)) print(int('123'))
print(int(False)) print(int('12.3'))
print(int(true)) print(int('True'))
print(int(false)) print(int('2+3j'))
print(int('PYTHON'))
Str Str Pure
Type Float Bool Complex Str Int Str Bool
Float Complex Str
int() P P NP P NP NP NP NP
P: Type Conversion Possible
NP: Type Conversion Not Possible
LITAM, PYTHON WORK SHEET, TPO 9
Task-10
Code Output Code Output
print(float(123)) print(float('123'))
print(float(True)) print(float('12.3'))
print(float(False)) print(float('True'))
print(float(true)) print(float('2+3j'))
print(float(2+3j)) print(float('PYTHON'))
Fill the Blanks with P (Possible Conversion) and NP (Not Possible Conversion)
Str Str Pure
Type Int Bool Complex Str Int Str Bool
Float Complex Str
float()
Task-11
Code Output Code Output
print(bool(123)) print(bool('123'))
print(bool(0)) print(bool('12.3'))
print(bool(123.45)) print(bool('True'))
print(bool(0.0)) print(bool('2+3j'))
print(bool(2+3j)) print(bool('PYTHON'))
Str Str Pure
Type Int Float Complex Str Int Str Bool
Float Complex Str
bool()
LITAM, PYTHON WORK SHEET, TPO 10
Task – 12
Code Output Code Output
print(complex(12)) print(complex('12'))
print(complex(0)) print(complex('1.3'))
print(complex(3.4)) print(complex('False'))
print(complex(True)) print(complex('2+3j'))
print(complex(False)) print(complex('PYTHON'))
Str Str Pure
Type Int Float Bool Str Int Str Bool
Float Complex Str
complex()
Task – 13
Code Output Code Output
print(str(12)) print(str(3+4j))
print(str(0)) print(str(4j))
print(str(3.4)) print(str(-4j))
print(str(True)) print(str(0j))
print(str(False)) print(str(-0-0j))
Type Int Float Bool Complex
str()
Task – 14
List out the errors with a clear description of what you get while
investigating the above-mentioned tasks.
LITAM, PYTHON WORK SHEET, TPO 11