MTA Revision v1
MTA Revision v1
Spring 23-24
Fall 23-24
Spring 22-23 Makeup
Summer 22-23 Makeup
MCQ
1- c
2- c
3- c
4- a
5- c
1- d
2- b
3- c
4- a
5- b
1- b
2- b
3- d
4- c
5- c
1- b
2- c
3- c
4- a
5- a
What is the output?
What will be shown on the screen when you execute the code?
x='5'+'6'
w=float(x[1])
y=25 6.0
z=int(x+'3') 56
if x=='11' or y==25: 25
568
z=z+5
else:
y= str(y)+x
print(w)
print(x)
print(y)
print(z)
x= "I have 100 reasons to quit!"
y=5 100
z=int( x[6:9]) 155155
w="15"+"5" 155
v=w Don't quit!
print(z**2) 10
print(w*2)
if v=='20':
z=z+5
else:
x="Don't quit!"
print(v)
print(x)
print(z)
Given the Python program below:
What is the expected output?
What does the u_items list represent?
a = [10,20,30,40,10,30,50,40]
d_items = []
u_items = [] The output:
for x in a: [20, 50]
if a.count(x)<=1: [10, 30, 40]
u_items.append(x) It represents the list of unique elements
elif x not in d_items: that are not repeated in the list a.
d_items.append(x)
print(u_items)
print(d_items)
Given the following python code. Write output?
L2=[]
L57=[]
L2: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
Lrest=[]
L57: [5, 7, 15]
for x in range(1, 21):
if (x%2!=1): Lrest: [1, 3, 9, 11, 13, 17, 19]
L2.append(x)
elif (x%7==0 or x%5 ==0):
L57.append(x)
else:
Lrest.append(x)
print ('L2:',L2)
print ('L57:',L57)
print ('Lrest:',Lrest)
Given the following python code. What will be the output if the user inputs “Anna”
Another Solution
grades = [25, 63, 75, 64, 72, 56, 90, 81, 76, 43, 60, 71]
total_grade = 0
for grade in grades: grades = [25, 63, 75, 64, 72, 56, 90, 81, 76,
total_grade += grade 43,60,71]
average_grade = round(total_grade / len(grades),2)
avgg = sum(grades)/len(grades)
highest_grade = grades[0] maximum = max(grades)
for grade in grades: print( round(avgg ,2))
if grade > highest_grade: print(format(maximum,'.2f'))
highest_grade = grade
my_list = [1, 2, 3, 4, 5]
new_element = 6
my_list+=[new_element]
print(my_list)
Write a program that takes in a list of names (a loop that prompts the user to enter a name, s or S to
stop) and removes all duplicates, then prints the resulting list. Hint: Use pretest check.
Another Solution
# Initialize an empty list to store the names
names_list = []
names_list = []
result_list =[]
# Prompt the user to enter names until 's' or 'S' is entered
name = input("Enter a name (or 's' to stop): ")
name = input("Enter a name (or 's' to stop): ")
while name.lower() != 's':
while name.lower() != 's':
names_list.append(name)
names_list.append(name)
name = input("Enter a name (or 's' to stop): ")
if result_list.count(name) == 0:
result_list.append(name)
# Remove duplicates from the list of names
name = input("Enter a name (or 's' to stop): ")
result_list = list(set(names_list))
print("The list without duplicates is: ", result_list)
# Print the resulting list
print("The list without duplicates is: ", result_list)
Write a program that calculates and prints the sum and the product of all the even numbers
between 1 and 12, included.
In your code, you should use one while loop and one if statement.
i=1
Sum = 0
product=1
print(list1)
print(list2)
print(intersect_List)
Find the error
Given the following program that should count the words that start with either "a" or "A" among the three
entered words.
count = 0
for i in range(1,3):
word = input("Enter a word: ")
if word[0].upper == 'A':
count = i
print("The number of words that start with 'a' or 'A' is:" +count)
However, the given code is not as expected and also includes an error.
You are asked to check the errors in the above code and write the correct code underlining the corrected
ones.
count = 0
for i in range(3):
word = input("Enter a word: ")
if word[0].upper() == 'A':
count += 1
print("The number of words that start with 'a' or 'A' is:", count)
Write python code for the
given flowcharts?
A- Write a python program that implements it.
B- What is the output of this program?
base = 2
power = 4
product = base
counter = 1
while counter < power:
product *= base
counter += 1
print(product)