Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON HELP! PLEASE HELP ME FIX THIS CODE! The assignment is posted as well. 2 #Find the sum of all even numbers between 0 and
PYTHON HELP! PLEASE HELP ME FIX THIS CODE!
The assignment is posted as well.
2 #Find the sum of all even numbers between 0 and 10 (inclusive) 3 def sumofAllEvenNumbersBetweenzeroAndTen sum 0 5 #Iterated through all even numbers between 0 and 10 using range method 6 #For the third parameter of range used step to jump over items. 7 #Add num to sum 8 sum num 9 print"Sum of all even numbers between 0 and 10 (inclusive) is %d" (sum) 10 11 #Find all powers of 2 from 0 to 16 12 def find Powers0fTwoFromZeroToSixteen(): print'' 0 power of 2 is 1" 13 14 #Iterated through the range of numbers 15 v for num in range 1,17 16 #Make an expression string like 2*2 using string multiply function ("a" x 3 "aaa") 17 #Strip out the leading '*'s and newlines from the expression string expression string ("2*"num0. rstrip strip (os.linesp) print''%d power of 2 is %d" num, eval(expression string) 18 19 20 #Function that calls itself 21 v def factorial (num) if num 0 or num 1: 22 return 1 23 return num factorial (num 1) 24 25 26 #Find factorial of all numbers between 1 and 10 (inclusive) 27 I could not use range method her so I used 11. 28 v def factoria10fAllNumbersBetweenoneAndTen for num in range 1,11 29 print Factorial of sod is sed" num, factorial(num) 30 31 32 sumofALLEvenNumbersBetweenzeroAndTen 33 find All Powers0fTwoFromZero ToSixteen 34 factorial0fAllNumbersBetweenoneAndTen 35Step 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