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
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