Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING PYTHON 3 4. What will the following code display? Def main(): Try: C = flo

ID: 3591470 • Letter: U

Question

USING PYTHON 3

4. What will the following code display?

Def main():

Try:

C = float(‘555SSS’)

print(‘The conversion is complete. ’)

except IOError:

print(‘This code caused an IOError. ’)

except ZeroDivisionError:

print(‘This code caused a zero division error. ’)

except:

print(‘An error occurred. ’)

print(‘el fin’)

main()

5. Calculate average of the following list?

numbers = [22, 42, 72 ,85, 58, 36, 63]

6. Assume the names variable references a list of strings. Write a program that determines whether

‘Ruby’ is in the names list. If it is, display the message ‘Hello Ruby’. Otherwise, display the message ‘I

don’t see any Ruby’.

7. Write a program to write a name_list with ‘Einstein’, ‘Newton’, ‘Copernicus’, and ‘Kepler’. Write a for

loop that displays last two characters of each name.

8. Write a function that creates a dictionary containing the following key-value pairs:

‘A’ 65

‘B’ 66

‘C’ 67

‘D’ 68

‘E’ 69

And, print values only.

9. Assume the variable dct references a dictionary. Write an if statement that determines whether the

key ‘Jim’ exists in the dictionary. If so, delete ‘Jim’ and its associated value.

10. Write a code to create 2 sets with the following integers: 10, 20, 30, 40, 50, 20 and 56, 25, 30, 32, 20,

43. Then calculate the union of 2 sets

Explanation / Answer

4

The output will be :

el fin

'An error occurred.’

because 555SSS is not a float in python .

5

numbers = [22, 42, 72 ,85, 58, 36, 63]
numbersSum = sum(numbers)
numbersLength = len(numbers)
numbersAverage = numbersSum / numbersLength
print (numbersAverage)