1) After the following code executes, what elements will be members of set3? set
ID: 3931155 • Letter: 1
Question
1) After the following code executes, what elements will be members of set3?
set1 = set(['d', 'e', 'f'])
set2 = set(['a', 'b', 'c', 'd', 'e'])
set3 = set2.difference(set1)
print(set3)
2) Write a statement that prints average score of Ethan.
scores = {'Kylie':[88, 92, 100], 'Peter':[95, 74, 81],
'James': [72, 88, 91], 'Ethan':[70, 75, 78]}
3) Identify at least five errors in the following code segment and re-write in correct form:
Import rand
main def ()
/* comments: guessing the throw of a die*/
y = random.uniform(1,6)
x = input(int(‘Enter a number from 1 to 6’))
if y = x
print(Sorry you have guessed wrong. Please try again)
else if y != x
print(‘You have guessed correctly”)
main()
4) Convert the following to a while-loop construct. You need not use all the defined variables.
def main ():
sum = 0
number_1 = input(“Enter a number”)
number_2 = input(“Enter a number”)
number_3 = input(“Enter a number”)
sum = number_1+number_2+number_3
print(sum)
main()
Explanation / Answer
1.
set1 = set(['d', 'e', 'f']) // Set contains def
set2 = set(['a', 'b', 'c', 'd', 'e']) // Set contains abcde
set3 = set2.difference(set1)
// set3 contains, the strings of set2 which not in set1.
print(set3) // It prints abc
Output :
abc
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.