1. Given the following snippets of code, evaluate the print statements: (assume
ID: 3914789 • Letter: 1
Question
1. Given the following snippets of code, evaluate the print statements: (assume python 3.Xx) Code: Output: z-1,4,5 s-"Text" for x.elem in x print (x elem, end print () for y elen in y: print(y.elem, end-,") print O for s.elem in s print (z elem, end-" print O for w.elem in w print (w-elem, end=",") (a) How many variables are there in the above code block? (b) What does the len) function of each variable return? (c) What is the data types of each of the variables? (d What is stored in y2[1]? y 010]? (e) What are the keys of the dictionary? What are the values? 2. Specification Write a program that allows the user to chose a movie based on a specific genre. Fill a dictionary with some of your own examples such that the user will type in a genre (Horror, Action, Drama, etc), and the program should display a list of movies for them to choose from, if they type a genre not supported..keep looping until the user provides a valid type. Have at least 3 genres and 3 examples. Enter a genre: Suspense Currently Not Available Enter a genre Documentry s Currently Not Available Enter a genre: Horror 1) Hellraiser 2) The Thing o 3) ShiningExplanation / Answer
If you post more than 1 question, as per chegg guidelines I have to solve only first question.
Ques 1.
The for loop traverse through the list one by one element. So, each for loop prints the lists with a comma(,) in between them.
The last for loop traverse through the keys in dictionary one by one.
So, the output is
1 , 4 , 3 , 2
'k' , 0 , (1 , 5)
'T' , 'e' , 'x' , 't'
'a' , 'b' , 'c'
(A) There are 5 variables in the above code.
(B) The len() variable return the length of each list.
So,
(c) The types are
(d) y[2][1] gives the 2nd element in the 3rd row.
So,
y[2][1] = 5
y[20][0] gives the 1 st element in the 1 st row.
So,
y[0][0] = 'k'
(e) The keys are 'a' , 'b' , 'c'.
Their correspondingvalues are 5 , [ 1 , 2 , 3 ] , x
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.