Question: Write a function sumDigits(number, numDigits) that returns the sum of the individualdigits in a parameter number that has numDigits digits. For example, sumDigits(1234, 4)should return

Write a function sumDigits(number, numDigits) that returns the sum of the individualdigits in a parameter number that has numDigits digits. For example, sumDigits(1234, 4)should return the value 1 + 2 + 3 + 4 = 10. (Hint: use a for loop and floor division (// and%).)

CAN SOMEONE EXPLAIN WHY I GOT DOES OUTPUT? I DO NOT UNDERSTAND HOW IT WORKS> I NEED EXPLANATION IN DETAIL

##this is what I wrote##

def sumDigit(number, numDigit):

sum=0

for i in range(numDigit):

digit=number%10

number=number//10

sum=sum+digit

return sum

print(sumDigit(369,3))

print(sumDigit(309,3))

print(sumDigit(300,3))

print(sumDigit(3804,4))

##output##

18 12 3 15

2. a. Write a function drawTriangle(length,t)that uses the turtle named t to draw a triangle. b. Write a function drawHexTriangle(length,t) uses the turtle named t to draw hexagonal by

calling drawTriangle method. c. Write a program that takes a length of a side from user and draw hexagonal triangle figure.

d. Write docstrings for each of your functions above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!