Question
Trace the code: sum = 20; numFound = 0 for ct in range(2, 17, 3): sum += ct if (ct %2 == 0) or (ct
sum = 20; numFound = 0 for ct in range(2, 17, 3): sum += ct if (ct %2 == 0) or (ct % 5==0): numFound +=1 print(ct, sum) print(numFound) |
| ||||||||||||||||||||||||
| a. Suppose the user is asked to enter a value for age, and they enter 21 What is the EXACT output? b. Correct the problems with the code. | ||||||||||||||||||||||||
| What is the output for the following input? x = 20; y = -1; z = 300 _____________________________ x = 20; y = 77; z = 300 _____________________________ x = -3; y = 77; z = 300 _____________________________ x = -3; y = -1; z = 300 _____________________________ | ||||||||||||||||||||||||
| Show the EXACT output: | ||||||||||||||||||||||||
| Show the EXACT output | ||||||||||||||||||||||||
6. def myFunc(x): tot = 0 for ct in range(x+1): tot += ct return tot result = myFunc(6) print (result) | 1. What is the output?____________________ 2. Correct the problem with the code: | ||||||||||||||||||||||||
7. def tripleItems(myList): for el in myList: el *= 3 scList = [11,21,31]; tripleItems(scList) print (scList) | Correct the problem with this code since the desired output is [33,63, 93] but instead, the output is [11,21,31]! | ||||||||||||||||||||||||
8. def someFunction(t1, t2, tot): tot = t1 + t2 return tot t1 = 100; t2 = 200; total = 0 someFunction(t1,t2,total); print(total) | Correct the problem with the code. The desired output is 300 but it does NOT produce that!
| ||||||||||||||||||||||||
9. scores = [100, 85,60] for sc in scores: sc += 10 print(scores) | Correct the code. It is supposed to add 10 to every score. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started