Fix This Python Code ! - Add Hungarian or Camel Notation - Fix Calling To Print
ID: 3818858 • Letter: F
Question
Fix This Python Code !
- Add Hungarian or Camel Notation
- Fix Calling To Print Function
-For The TwoPower Function the range needs to be changed to (1,17), 2 to the power of zero should be 1
- Any additional advise or help would be very appreciated thank you!
1 /usr/bin/python 2 coding: utf-8 3 #Global 4 Su 0 5 value 1 7 fact 1 9 Define's Sum of Even Numbers 10 def SumofEvenNumbers 11 Sum 0 12 13 14 This Function Sets The Range Numbers For The Previous Function To Utilize 15 for i in range (0, 11 if i 2 0: 16 sum sum +i 17 print sum of even numbers is sum 18 19 20 This Function Defines Two Powers and Their Value 21 def Two Powers 22 value 1 23 24 25 This Function Sets The Range Numbers For The Previous Function To Utilize 26 for i in range(1, 17 value value 2 27 28 #Power Values 29 if value 0: value 1 30 31 print '2 0 value 32 print "2 i, 3', value 33 34 Set's Factorial Information For Program 35 def Factorial 36 fact 1 37 38 39 40 41 for i in range (1, 11 if i 1: 42 print i, k 43 44 else 45 46 while n i: fact fact n 47 48 n 49 print i fact 50 fact 1 51 52 SumofEvenNumbers 53 Two Powers 54 Factorial() 55Explanation / Answer
# pastebin linkf for code: https://pastebin.com/x2y1UGeN
#!/usr/bin/python
#-*- coding: utf-8 -*-
#Global
sum = 0
value = 1
k = 1
fact = 1
# Define's Sum of Even numbers
def sumOfEvenNumbers():
sum = 0
i = 0
# This Function Sets The Range of Numbers For The Previous Function To Utilize
for i in range(0, 11):
if i % 2 == 0:
sum = sum + i
print 'sum of even numbers is = ', sum
# This Function Defines Two Powers and Their Value
def twoPowers():
value = 0
# This function Sets the Range of Numbers For The Previous Function to Utilize
for i in range(1, 17):
value = value*2
#Power Values
if value == 0:
value = 1
print '2^0 = ', value
else:
print '2^', i, ' = ', value
# Set's Factorial Information For Program
def factorial():
i = 0
fact = 1
k = 1
for i in range(1,11):
if i == 1:
print i, '! = ' , k
else:
n = 1
while n <= i:
fact = fact*n
n = n+1
print i, '! = ', fact
fact = 1
sumOfEvenNumbers()
twoPowers()
factorial()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.