An introductory course to the Python 3 programming language, with a curriculum aligned to the Certified Associate in Python Programming (PCAP) examination syllabus (PCAP-31-02).
https://knowledgebase.hyperlearning.ai/courses/introduction-to-python
https://knowledgebase.hyperlearning.ai/courses/introduction-to-python/modules/11/pcap-practice-exam
In this final module of our Introduction to Python course, we will consolidate everything that we have learnt by taking a practice Certified Associate in Python Programming (PCAP) examination paper.
2 ** 3 ** 2 ** 1
print("Peter's sister's name's \"Anna\"")
print('Peter\'s sister\'s name\'s \"Anna\"')
i = 250
while len(str(i)) > 72:
i *= 2
else:
i //= 2
print(i)
n = 0
while n < 4:
n += 1
print(n, end=" ")
x = 0
y = 2
z = len("Python")
x = y > z
print(x)
print(type(x))
Val = 1
Val2 = 0
Val = Val ^ Val2
Val2 = Val ^ Val2
Val = Val ^ Val2
print(Val)
z, y, x = 2, 1, 0
x, z = z, y
y = y - z
x, y, z = y, z, x
print(x, y, z)
a = 0
b = a ** 0
if b < a + 1:
c = 1
elif b == 1:
c = 2
else:
c = 3
print(a + b + c)
i = 10
while i > 0 :
i -= 3
print("*")
if i <= 3:
break
else:
print("*")
# Example 1
for i in range(1, 4, 2):
print("*")
# Example 2
for i in range(1, 4, 2):
print("*", end="")
# Example 3
for i in range(1, 4, 2):
print("*", end="**")
# Example 4
for i in range(1, 4, 2):
print("*", end="**")
print("***")
list(range(1, 4, 2))
print('N/A')
x = "20"
y = "30"
print(x > y)
s = "Hello, Python!"
print(s[-14:15])
print(s[0:30])
lst = ["A", "B", "C", 2, 4]
del lst[0:-2]
print(lst)
dict = { 'a': 1, 'b': 2, 'c': 3 }
for item in dict:
print(item)
s = 'python'
for i in range(len(s)):
i = s[i].upper()
print(s, end="")
lst = [i // i for i in range(0,4)]
sum = 0
for n in lst:
sum += n
print(sum)
lst = [[c for c in range(r)] for r in range(3)]
for x in lst:
for y in x:
if y < 2:
print('*', end='')
lst = [2 ** x for x in range(0, 11)]
print(lst[-1])
lst1 = "12,34"
lst2 = lst1.split(',')
print(len(lst1) < len(lst2))
def fun(a, b=0, c=5, d=1):
return a ** b ** c
print(fun(b=2, a=2, c=3))
x = 5
f = lambda x: 1 + 2
print(f(x))
from math import pi as xyz
print(pi)
print('N/A')
from random import randint
for i in range(10):
print(random(1, 5))
x = 1 # line 1
def a(x): # line 2
return 2 * x
# line 3
x = 2 + a(x) # line 4
print(a(x)) # line 5
a = 'hello' # line 1
def x(a,b): # line 2
z = a[0] # line 3
return z # line 4
print(x(a)) # line 5
s = 'SPAM'
def f(x):
return s + 'MAPS'
print(f(s))
print('N/A')
def gen():
lst = range(5)
for i in lst:
yield i*i
for i in gen():
print(i, end="")
print('N/A')
print('N/A')
print('N/A')
# Example 1
x = 1
y = 0
z = x%y
print(z)
# Example 2
x = 1
y = 0
z = x/y
print(z)
x = 0
try:
print(x)
print(1 / x)
except ZeroDivisionError:
print("ERROR MESSAGE")
finally:
print(x + 1)
print(x + 2)
class A:
def a(self):
print("A", end='')
class B(A):
def a(self):
print("B", end='')
class C(B):
def b(self):
print("B", end='')
a = A()
b = B()
c = C()
a.a()
b.a()
c.b()
try:
print("Hello")
raise Exception
print(1/0)
except Exception as e:
print(e)
# Example 1
class CriticalError(Exception):
def __init__(self, message='ERROR MESSAGE A'):
Exception.__init__(self, message)
raise CriticalError
raise CriticalError("ERROR MESSAGE B")
# Example 2
class CriticalError(Exception):
def __init__(self, message='ERROR MESSAGE A'):
Exception.__init__(self, message)
raise CriticalError("ERROR MESSAGE B")
file = open(test.txt)
print(file.readlines())
file.close()
f = open("file.txt", "w")
f.close()