[go: up one dir, main page]

0% found this document useful (0 votes)
6 views13 pages

Float Divisions So 10/5 Is A Float or 2.0

The document contains a series of exam questions related to Python programming, covering topics such as variable assignments, error identification in code, data structures, and function outputs. Each question is followed by multiple-choice answers, with explanations provided for some questions. The content is aimed at assessing understanding of Python syntax and logic.

Uploaded by

Leanne Layug
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

Float Divisions So 10/5 Is A Float or 2.0

The document contains a series of exam questions related to Python programming, covering topics such as variable assignments, error identification in code, data structures, and function outputs. Each question is followed by multiple-choice answers, with explanations provided for some questions. The content is aimed at assessing understanding of Python syntax and logic.

Uploaded by

Leanne Layug
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

EXAM BIS JANUARY 2023

QUESTI ON 1

1. a, b = 10,5
2. c = a/b

What is the value assigned to variable ‘c’ after executing the code?

0. ‘2’
0. 2
0. 2.0
0. 5
0. None of the answers above are correct

-> float divisions so 10/5 is a float or 2.0

QUESTION 2

number = input(“Please provide a random number: ”)


if int(number) > 3
print(number, “is greater than 3.”)
elif int(number) < 3:
print(Number, “is less than 3.”)
elif int(number) = 3:
print(number, “is equal to 3.”

how many errors occur in the Python code given above?


0. 3
0. 4
0. 5
0. 6
0. 7
solution:
number = input(“Please provide a random number: ”)
if int(number) > 3:
print(number, “is greater than 3.”)
elif int(number) < 3:
print(Number, “is less than 3.”)
elif int(number) = 3:
print(number, “is equal to 3.”)

QUESTION 3

a = 50
b = ‘10’ 2 values in the string (1 and 0) ‘ ‘ means string
c = a // len(b) 50//2
for I in range (2) ← the 2 means you have to loop it twice
c %= 9
print (c)

ok so after we calculated 50//2 which is 25, we look at the for-loop


the for loop tells us that it will get repeated twice, in this case it doesn’t matter but i will
still show you so you understand for tomorrow

the for loop says that c%=9


so we know c = 25 and we know we have to divide with 9. the question is: what is the
remainder? 25/9 = 18/9 with remainder 7
-> answer of our modulo = 7 , do we do it until its under 9? why twice ahhhh i see it

we loop it a second time now (though there is no point)


the c now has value 7
7%= 9 = 0 with remainder 7, the remainder will therefore always be 7, doesn’t matter how
many times you loop it

what is the output of the code above?


A. 25
B. 7
C. 5
D. 2
E. None of the answers above are correct
QUESTION 4

print (bool (“ “) )

what is the output of the code above?


A. 1
[B.] “False ”
B.[C.] False
C.[D.] “True”
D.[E.] True

QUESTION 5

which python data structure or structures is/are mutable and contain duplicate values?
A. set
B. list
C. tuple
D. set and list

set and tuple


QUESTION 6

First_number = 3 -> integer


Last_number = “14” -> string
print (“The result is “ + ____ (1) First_number ____ (2) + ____ (3) Last_number ____ (4) +
“.”)

if you change the first one to string, the integer, you can leave number 3 blank as it’s
already a string and then you leave 4 blank too
that’s correct

i am just thinking, you either change one to string and leave the other be, or you rewrite
the second one as string too but it won’t make a big difference as it already is a string
exactly ohhhhhh no no no pardon i see the answers now theres a ) as an answer

i thought it was only str or itr or blank


first space is 100% string cause it’s a sum of strings and the first number is written as an
integer so we have to convert it to string ok ok
print (“The result is “ + _str(___ First_number ___this?_ + ____ Last_number __))__ + “.”)

so you got this one?


i am just questioning at the moment, i think 1 is also possible as you take the string of an
integer, you don’t close the string yet and then you rewrite the last number as an integer
so as final result you get the sum of 3 string and the middle string is a string of the sum of
2 integers so i would say A and C are both correct i dont think so since last number is
ready a strin question 7 is easy ahn ok ok, then !8
choose what should be filled out in the empty spaces for the code to give the following
output when executed: “The result is 314.”
A. (1) str(
(2) should be left blank
(3) int(
(4) ))
B. (1) str(
(2) )
(3) str(
(4) )
C. (1) str(
(2) )
(3) should be left blank
(4) should be left blank
D. (1) str(
(2) )
(3) int(
(4) )
E. 2 of the above answers are correct

ok ok i explain
the general rule is you cannot take the sum of a string and an integer, they all have to
have the same form so integer + integer or string + string or float + float
scroll up if you understood, stay when you are lsot

QUESTION 7

Answer = “False”
if Answer:
print (“The answer is correct.”)

what is the output of the code above?


A. The answer is correct.
B. False
C. There is no output
D. None
E. Error
ah no just beweetn brakent
i explain very shortly
just replace the answer = with cows
so answer = “cows”
cows example, wait, cause the false is there to confuse you
if answer;
print(“ the answer is correct”)
-> answer is not an empty string so the if statement is correct so we just print the “the
answer is correct”

that’s the logic behind it


“false” is a non-empty string so the answer is always correct and the if can get printed
an if statements states that if a certain thing it’s true, a certain result will get printed
a non empty string means the string is not empty but has a value (a letter, number, etc)
okoko got it kinda i just think it printed (“”) since its the last thing it asked if it wanted to
print “False” it would be print(Answer) ? hmmmm the thing is if the string was empty, i
think it would have given an error but you got a point
just look at the print statement in this case cause it doesn’t point back to the false thing
just know an empty string is always an error or a false boolean

uh huh exactly im so smart. whats an empty string example?

bool(“”) is empty FALSE (represents 0)


bool(“ “) is not empty cause there is a space this would be true? or false? TRUE (represents
1)
ok your business is finished
let’s do another exercise?
just in an exercise
answer = “”
print (answer) = error?
i think it will be error cause it’s an empty string and not written as a boolean

QUESTION 8

list_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


list_B = (list_A [9: -8: -2])
print (list_B [2])

what is the output of the code above?


A. 8
B. 5
C. 6
D. 7
E. Error
you need help? he is dead
ok wait, it’s too much to type but i hope you understand ehhh

so with the numbers of A you make a new list. you start with the 9th index (number 10) and
count back with jumps of 2 to index -8. the minus sign means you stop before the index so
number 2 in this case is not included.

so it would look like this


list A: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
index: 0 1 2 3 4 5 6 7 8 9

8 indices back starting from index 9 = index 1 (number 2).


number 2 is not included as the it states we go to index -8 so it’s exclusive (stops before the
element)
if we take steps of 2 indices:
list_A = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
index: 0 1 2 3 4 5 6 7 8 9

so list_B looks like [ 10, 8, 6, 4]


-> we start with 10 cause the syntax of the second line is start:stop:step
we have to print the second index of list_B
so list_B= [ 10, 8, 6, 4]
index: 0 1 2 3

output = 6

You basically have 3 steps


because the starting index is 10, you reverse the whole list and start with 10

second step: you move 8 indexes to know the ending index (ending index is number 2, or
index 1). BUT the ending index is exclusive as the number is negative

step 3: to define our final list_b, we look at the steps. we have to take jumps of 2 indices,
starting at 10 so 10 - 8 - 6 - 4
-> 2 NOT includes as 2 is the ending index that is EXCLUSIVE

so or list_B is [10, 8, 6, 4]
-> the print statement asks the 2 index, the 2 index equals the third number so the answer is
6
list_B = (list_A [9: -8: -2])

QUESTION 9

def TV_show (name):


if name in [“David Schwimmer”, “Courteney Cox”, “Matthew Perry”]:
return “Friends”
if name in [“Bryan Cranston”, “Aaron Paul”]:
return “Breaking bad”
if name in [“Uraula Corbero”, “Alvaro Morte”, “Pedro Alonso”]:
return “La Casa de Papel”
if name in [“Courteney Cox”, “Busy Philipps”]:
return “Cougar Town”

TV_show (“Pedro Alonso”)


print(TV_show(“Courteney Cox’))

what is the output of the code above?


A. La Casa de Papel
Friends
Cougar Town
B. Friends
Cougar Town
C. La Casa de Papel
Friends
D. Friends
E. La Casa de Papel
QUESTION 10
lines = ____ (1)
i=0
with open (‘filename.txt’) as f:
for line in f:
if i in lines:
print (line)
i ____ (2)

choose what should be filled out in the empty spaces for the code to give the 4 th, 5th, 6th and
7th line of the .txt file ‘filename’ as output?

A. (1) [4, 5, 6, 7]
(2) += 1
B. (1) (4, 5, 6, 7)
(2) += 1
C. (1) [3, 4, 5, 6]
(2) += 1
D. (1) [4, 5, 6, 7]
(2) *= 1
E. (1) [3, 4, 5, 6]
(2) *= 1

QUESTION 11
1 sentence = ‘as he crossed toward the pharmacy at the corner he
2 involuntarily turned his head because a burst of light that had
3 ricocheted from his temple and saw with that quick smile with which we
4 greet a rainbow or a rose a blindingly white parallelogram of sky being
5 unloaded from the van-a dresser with mirrors across which as across a
6 cinema screen passed a flawlessly clear reflection of boughs sliding
7 and swaying not arboreally but with a human vacillation produced by
8 the nature of those who were carrying this sky these boughs this gliding
9 façade’
10 sentence_list = sentence.split (‘ ’)

how can the code on line 10 be reversed, i.e. how can we turn the value stored in variable
‘sentence_list’ back into the value stored in the variable ‘sentence’?
A. sentence_list.split (‘ ‘)
B. sentence_list.split (‘,’)
C. ‘,’ join (sentence_list)
D. ‘’ join (sentence_list)
E. several of the above answers are correct
QUESTION 12

Home Sale price (100$) Size (sqft) Age (years)


Avalon 2050 2650 13
Cross Winds 2080 2600 *

The White House 2150 2554 6


The Rectory 2150 2921 3
Larchwood 1999 2580 4
Orchard House 1900 2580 4
Shanri-La 1800 2774 2
The Stables 1560 1920 1
Cobweb Cottage 1450 2150 *
Nairn House 1449 1710 1

how can the data in the table above be represented correctly in Python without loss of any
of the information? the potential answers only include an illustrative example, so you may
assume that the structure used for that example can be applied to all data available in the
table above.

A. Houses = {“Avalon”: {“Sale price (100$)”: 2050, “Size (sqft)”: 2650, “Age (years)”: 13},
“Cross Winds”: {…}}
B. Houses = (“Avalon”, 2050, 2650, 13, “Cross Winds”, …)
C. Houses = [{“House”: ”Avalon”, “Sale price (100$)”: 2050, “Size (sqft)”: 2650, “Age
(years)”: 13}, {“House”: “Cross Winds”: …}]
D. Houses = {[“House”: ”Avalon”, “Sale price (100$)”: 2050, “Size (sqft)”: 2650, “Age
(years)”: 13], [“House”: “Cross Winds”: …]}
E. 2 of the answers above are correct
QUESTION 13

def Unique_numbers (sum):


y = sum ____ (1)
return ____ (2)

x = “ 8 + 5 + 13 + 17 + 3 + 29 + 5 + 31 + 0 + 17 + 29 “
print (Unique_numbers (x))

choose what should be filled out in the empty spaces for the code to give the amount of
unique numbers that are separated from each other with a “+” sign stored in variable “x” as
output.
A. (1) .split(“+”)
(2) len(y)
B. (1) .split(“+”)
(2) len(set(y))
C. (1) .split()
(2) len(set(y))
D. (1) .split()
(2) len(y)
E. none of the answers above are correct

QUESTION 14

Football_data = {
“Goals”: 2,
“Assists”: 4,
“Interceptions”: 22,
“Average performance rating”: “Good”
}

how can we access the value for key “Interceptions” in the following Python Dictionary?
A. Football_data [“Interceptions”]
B. Football_data (“Interceptions”)
C. Football_data [Interceptions]
D. Football_data (Interceptions)
E. Several of the answers above are correct
QUESTION 15

names = [“John”, “Jane”, “Doe”]


for name in names:
if name in [“John”, “Doe”]:
for x in range (2):
i=0
while i < 6:
print (name, x, i)
i += 1

else:
x=6
if x == i:
print (name)

how often will the names “John”, “Jane” and “Doe” be given as output?
A. John: 10 times
Jane: 1 time
Doe: 10 times
B. John: 12 times
Jane: 1 time
Doe: 12 times
C. John: 10 times
Jane: 0 time
Doe: 10 times
D. John: 12 times
Jane: 0 time
Doe: 12 times
E. John: 8 times
Jane: 0 time
Doe: 8 times

You might also like