Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Python is one of the most popular coding languages today; it’s categorized as a vital benchmark of computer science knowledge in industry interviews. This highly interactive course is an accelerated introduction to Python. It is intended for users who are already familiar with the fundamentals of programming and aims to teach the Python programming language using a practical approach. It not only covers the basic Python syntax but also teaches methods specific to Python3. With most companies already switching from Python2 to Python3, this version of Python is the future.
Before moving on to more complex and powerful tools, we’ll examine the fundamentals of the language. You can also experiment with the code provided and, therefore, gain a higher understanding of how things work. This course is perfect for anyone who works as a Python developer and wants to recognize its full potential. Happy learning!
Answer:
def checkParity(n):
result = (n % 2) ## Update result according to the parity
return result
Answer:
def inRange(x, y):
return (x < 1/3 < y)
Answer:
def getStr(s):
s=s[:1] + s[0] + s[1:]# Transform the string
s=s[:1] + s[0] + s[1:]
s=s[:3] + s[3] + s[3:]
s=s[:3] + s[3] + s[3:]
s=s[:6] + s[6] + s[6:]
s=s[:6] + s[6] + s[6:]
# Update the length of string
strlen = len(s)
return [s, strlen]
Answer:
def findOccurence(s):
a = s.find("b") # find first occurrence of "b" in the string
b = s.find("ccc") # find first occurence of "ccc" in the string
return [a, b]
Answer:
def changeCase(s):
a=s.upper() ### convert string to "AAA BBB CCC"
b=s.lower() ### convert string to "aaa bbb ccc"
return [a, b]
Q1. What is the output of the following code
print("Hello World" + "Hello World" + "Hello World" * 2)
Q2. How can you calculate the length of a string str
in python?
Answer:
def getSubList():
l = [1, 4, 9, 10, 23]
l1 = l[0:3]
l2 = l[3:]
return [l1, l2]
Answer:
def AppendtoList():
l = [1, 4, 9, 10, 23]
l.append(90)
return l
Answer:
def getAverage():
l1 = [1, 4, 9, 10, 23]
avg = sum(l1) / len(l1)
return avg
Answer:
def removeList():
l1 = [1, 4, 9, 10, 23]
l2 = [4, 9]
l1.remove(l2[0])
l1.remove(l2[1])
return l1
l1 = removeList()
print(l1)
Answer:
def getSquare():
l1 = [x*x for x in range(1, 11)]
return l1
Answer:
def getCube():
l1 = [x*x*x for x in range(1, 21)]
return l1
Answer:
def ListofEvenOdds():
l1 = []
l2 = []
l1 = [x for x in range(0,21) if (x%2==0)]
l2 = [x for x in range(0,21) if (x%2!=0)]
return[l1, l2]
print(ListofEvenOdds())
Answer:
def evenSquareSum():
even = [ x * x for x in range(0,21) if x % 2 == 0]
return sum(even)
Answer:
def getSquare():
l1 = [x * x for x in range(0, 21, 2) if x % 3 != 0]
return l1
Q1. What should be the output of the following code?
print([5,6,7] + [8,9,10])
Q2. Given the list. How can you add an item “baseball” in the list?
list = [“basketball”, “cricket”, “badminton”]
Q3. What is the output of the following code?
S = [x**2 for x in range(10)]
print(S)
Q4. What is the output of the following code?
list = [n**2 for n in range(10) if n % 2 == 0]
print(list)
Answer:
import math
def findGCD(a, b): ## Alter the declaration to get the function to take two input arguments
return math.gcd(a, b)
Answer:
import math
def calculateSinCosTan(x):
sine = math.sin(x)
cos = math.cos(x)
tan = math.tan(x)
return [sine, cos, tan]
Answer:
def findMaximum(x,y):
max2 = max(x, y) #create a variable max2
return max2 #returns the maximum of two numbers x and y
Answer:
def isDivisble(x, y):
if x % y == 0:
return True
else :
return False
Answer:
def fibonacci(n):
if n <= 1:
return n
else:
return(fibonacci(n-1) + fibonacci(n-2))
Answer:
def sum_N_Numbers (n):
if n <= 1:
return n
else:
return n + sum_N_Numbers (n-1)
Q1. What is the output of the following function?
def function(fruit = "Orange"):
print("I like " + fruit)
function("Banana")
function("Peach")
function()
function("Mango")
I like Banana
I like Peach
I like Orange
I like Mango
I like Banana
I like Peach
I like Peach
I like Mango
I like Banana
I like Peach
I like Mango
Q2. What is the output of the following function?
def function(x):
return 5 +x
print(function(2))
print(function(4))
print(function(6))
7
9
11
5
5
5
Q3. What is the output of the following code?
def recursion(k):
if(k>0):
result = k+recursion(k-1)
else:
result = 0
return result
print(recursion(2))
Answer:
def sumList(l):
sum = 0
for x in l:
sum += x
return sum
Answer:
def findMaximum(list):
maximum = list[0]
for number in list:
if number > maximum:
maximum = number
return maximum
Answer:
def findMaximumValueIndex(list):
maximum = list[0]
index = 0
for i, value in enumerate(list):
if value > maximum:
maximum = value
index = i
return [index, maximum]
Answer:
def reverse(list):
length = len(list)
s = length
new_list = [None]*length
for item in list:
s = s - 1
new_list[s] = item
return new_list
Answer:
def isSorted(list):
flag = 0
i = 1
while i < len(list):
if(list[i] < list[i - 1]): # compare with the previous element
flag = 1
i += 1
if (not flag) :
return True
else :
return False
Answer:
def hasDuplicates(list):
flag = 0
for i in range (len(list)):
for j in range (i + 1, len(list)):
if (list[i] == list[j]):
flag = 1
if (flag == 1):
return True
else:
return False
Answer:
def printEvenOdd(n):
while(n>0):
if (n%2==0):
print ("Even number:",n)
else:
print ("Odd number:",n)
n=n-1
Q1. What is the output of the following code?
for a in "Python":
print (a)
Q2. What is the output of the following code?
Languages = ["Python", "Java", "R"]
for x in Languages:
if x == "Java":
break
print(x)
Q3. What is the output of the following code?
i = 1
while i < 7:
print(i)
if (i == 3):
break
i += 1
1
2
3
1
2
3
4
5
6
Q4. What is the output of the following code?
i = 1
while i <= 7:
i += 1
if (i == 3):
continue
print(i)
1
2
3
2
4
5
6
7
8
Answer:
def lengthDictionary(Students):
return len(Students)
Answer:
def calculateAvg(ages):
length = len(ages)
return(sum(ages.values()) / length)
Answer:
def oldestStudent(ages):
value = list(ages.values())
key = list(ages.keys())
return key[value.index (max(value))]
Answer:
def updateAges(ages, n):
new_ages = {}
for word in ages:
new_ages[word] = ages[word] + n
return new_ages
Answer:
def totalStudents(students):
return(len(students.keys()))
Answer:
def calculateAverageAge(students):
result = {}
add_age = 0
for thing in students.values():
age = thing['age']
add_age = add_age + age
return(add_age / len(students.keys()))
Answer:
def find_students(address, students):
names = []
for key, subdict in students.items():
for sublist in subdict.values():
if (sublist == address):
names.append(key)
return sorted(names)
Q1. What is the output of the following code?
Dict = { 'Dict1': {'Fruitname': 'Mango', 'season': 'Summer'},
'Dict2': {'Fruitname': 'Orange', 'season': 'Winter'}}
print(Dict['Dict1']['Fruitname'])
print(Dict['Dict2']['season'])
Q2. What is the output of the following code?
Dict1 = {
"FruitName": "Mango",
"season": "Spring",
}
Dict1["season"] = "Summer"
print(sorted(Dict1.values()))
Q3. What is the output of the following code?
Dict1 = {
"FruitName": "Mango",
"season": "Spring",
}
Dict1.pop("season")
print(Dict1.values())
Q4. What is the output of the following code?
Dict1 = {
"FruitName": "Mango",
"season": "Spring",
}
Dict1.clear()
print(Dict1)
Answer:
class Rectangle:
def __init__(self, x1, y1, x2, y2): # class constructor
if x1 < x2 and y1 > y2:
self.x1 = x1 # class variable
self.y1 = y1 # class variable
self.x2 = x2 # class variable
self.y2 = y2 # class variable
else:
print("Incorrect coordinates of the rectangle!")
Answer:
class Rectangle:
def __init__(self, x1, y1, x2, y2): # class constructor
if x1 < x2 and y1 > y2:
self.x1 = x1 # class variable
self.y1 = y1 # class variable
self.x2 = x2 # class variable
self.y2 = y2 # class variable
else:
print("Incorrect coordinates of the rectangle!")
def width(self):
return self.x2 - self.x1
def height(self):
return self.y1 - self.y2
Answer:
class Rectangle:
def __init__(self, x1, y1, x2, y2): # class constructor
if x1<x2 and y1>y2:
self.x1 = x1 # class variable
self.y1 = y1 # class variable
self.x2 = x2 # class variable
self.y2 = y2 # class variable
else:
print("Incorrect coordinates of the rectangle!")
def width(self):
return self.x2-self.x1
def height(self):
return self.y1-self.y2
def area(self):
return self.width()*self.height()
def perimeter(self):
return 2*self.width()+2*self.height()
Answer:
class Rectangle:
def __init__(self, x1, y1, x2, y2): # class constructor
self.x1 = x1 # class variable
self.y1 = y1 # class variable
self.x2 = x2 # class variable
self.y2 = y2 # class variable
def __str__(self):
return(str(self.x1)+', '+str(self.y1)+', '+str(self.x2)+', '+str(self.y2))
#write your code here
Answer:
class Rectangle:
def __init__(self, x1, y1, x2, y2): # class constructor
self.x1 = x1 # class variable
self.y1 = y1 # class variable
self.x2 = x2 # class variable
self.y2 = y2 # class variable
def width(self):
return self.x2 - self.x1
def height(self):
return self.y2 - self.y1
def area(self):
return self.width() * self.height()
class Square(Rectangle):
def __init__(self, x1, y1, length):
x2 = x1 + length
y2 = y1 + length
super().__init__(x1, y1, x2, y2)
Q1. In Python __init__
is
Q2. With the following code, which of the options is true?
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
class Student(Person):
def __init__(self, fname, lname, year):
super().__init__(fname, lname)
self.batch= year
x = Student("Alex", "Vice", 2019)
x = Student("Anna", "Bate", 2018)
print(x.batch)
Answer:
class MyRange:
def __init__(self, n):
self.n = n
def __iter__(self):
return self
def next(self):
evenArray = [] # next method returns this list
for i in range(1, self.n+1):
if i % 2 is 0: # checks if number is even
value = i
evenArray.append(i) # adds the even number to the list
else: # number was odd
i+=1
return evenArray
myrange = MyRange(8)
print (myrange.next())
Answer:
class MyRange:
def __init__(self, n):
self.n = n
def __iter__(self):
return self
def next(self):
myArray = []
for i in range(self.n, -1, -1): # from n to 0
myArray.append(i) # adds the even number to the list
return myArray
Answer:
class MyRange:
def __init__(self, n):
self.n = n
def __iter__(self):
return self
def next(self):
myArray = []
for i in range(self.n): # from n to 0
if i == 0 or i == 1:
myArray.append(i) # adds the even number to the list
else:
myArray.append(myArray[i-2]+myArray[i-1])
return myArray
myrange = MyRange(8)
print(myrange.next())
Answer:
def odd(n):
for value in range(n + 1):
if value % 2 is not 0:
yield value
Answer:
def reverse(n):
for value in range(n, -1, -1):
yield value
Answer:
def fibonacci(n):
myArray = []
for i in range(n):
if i is 0 or i is 1:
myArray.append(i)
yield i
else:
x = myArray[i-2] + myArray[i-1]
myArray.append(x)
yield x
Q1. Which of the following statements allow you to execute an asynchronous function myPrint(x)
once?
import asyncio
async def myPrint(x):
print(x)
await asyncio.sleep(1)
return
loop = asyncio.get_event_loop()
results = loop.run_until_complete(myPrint(1))
loop.close()
import asyncio
async def myPrint(x):
print(x)
await asyncio.sleep(1)
return
loop = asyncio.get_event_loop()
results = loop.run_until_complete(asyncio.gather(myPrint(1))
myPrint(2))
loop.close()
Q2. Which of the following statements allow you to execute an asynchronous function myPrint(x)
multiple times?
import asyncio
async def myPrint(x):
print(x)
await asyncio.sleep(1)
return
loop = asyncio.get_event_loop()
results = loop.run_until_complete(myPrint(1))
loop.close()
import asyncio
async def myPrint(x):
print(x)
await asyncio.sleep(1)
return
loop = asyncio.get_event_loop()
results = loop.run_until_complete(asyncio.gather(myPrint(1), myPrint(2)))
loop.close()
I hope this Full Speed Python Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>