hw03.py - HW_SOURCE_FILE ='hw03.py Questions from operator import add mul sub square = lambda x x x identity = lambda x x triple = lambda x 3 x

# hw03.py - HW_SOURCE_FILE ='hw03.py Questions from operator...

• Homework Help
• 4

This preview shows page 1 - 3 out of 4 pages.

HW_SOURCE_FILE = 'hw03.py' ############# # Questions # ############# from operator import add, mul, sub square = lambda x: x * x identity = lambda x: x triple = lambda x: 3 * x increment = lambda x: x + 1 def has_seven(k): """Returns True if at least one of the digits of k is a 7, False otherwise. >>> has_seven(3) False >>> has_seven(7) True >>> has_seven(2734) True >>> has_seven(2634) False >>> has_seven(734) True >>> has_seven(7777) True >>> from construct_check import check >>> check(HW_SOURCE_FILE, 'has_seven', ... ['Assign', 'AugAssign']) True """ if k % 10 == 7: return True if k > 10 : return has_seven(k//10) else: return False from construct_check import check check("hw03.py", 'has_seven', ['Assign', 'AugAssign']) def pingpong(n): """Return the nth element of the ping-pong sequence. >>> pingpong(7) 7 >>> pingpong(8) 6 >>> pingpong(15) 1 >>> pingpong(21) -1 >>> pingpong(22) 0 >>> pingpong(30) 6 >>> pingpong(68) 2
>>> pingpong(69) 1 >>> pingpong(70) 0 >>> pingpong(71) 1 >>> pingpong(72) 0 >>> pingpong(100) 2 >>> from construct_check import check >>> check(HW_SOURCE_FILE, 'pingpong', ['Assign', 'AugAssign']) True """ def helper(x, sum, direction): if sum == n: return x if sum % 7 == 0 or has_seven(sum): if direction // 10 % 10 == 1: return helper(x-1, sum +1,-direction) else: return helper(x+1, sum +1,-direction) if direction < 0:

#### You've reached the end of your free preview.

Want to read all 4 pages?

• Spring '14
• BERRY,ME

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern