The first 2 questions are non-coding - WWPD (What Would Python Display?)
Q3: Fix the Bug
defboth_positive(x,y):"""Returns True if both x and y are positive.>>> both_positive(-1, 1) False>>> both_positive(1, 1) True """return x and y >0# You can replace this line!
Q3: Solution
defboth_positive(x,y): """Returns True if both x and y are positive. >>> both_positive(-1, 1) False >>> both_positive(1, 1) True """return x >0and y >0# You can replace this line!
Q4: Sum Digits
defsum_digits(n):"""Sum all the digits of n.>>> sum_digits(10) # 1 + 0 = 1 1>>> sum_digits(4224) # 4 + 2 + 2 + 4 = 12 12>>> sum_digits(1234567890) 45>>> x = sum_digits(123) # make sure that you are using return rather than print>>> x 6 """"*** YOUR CODE HERE ***"
Q4: Solution
defsum_digits(n):"""Sum all the digits of n.>>> sum_digits(10) # 1 + 0 = 1 1>>> sum_digits(4224) # 4 + 2 + 2 + 4 = 12 12>>> sum_digits(1234567890) 45>>> x = sum_digits(123) # make sure that you are using return rather than print>>> x 6 """"*** YOUR CODE HERE ***"if n <10:return n last_digit = n %10return last_digit +sum_digits(n //10)