Skip to content

Commit 8feecad

Browse files
committed
added warmup-1 problems
1 parent ab30218 commit 8feecad

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Solutions/warmup-1/diff21.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Given an int n, return the absolute difference between n and 21,
2+
# except return double the absolute difference if n is over 21.
3+
4+
# diff21(19) → 2
5+
# diff21(10) → 11
6+
# diff21(21) → 0
7+
8+
9+
def diff21(n):
10+
if n > 21:
11+
return 2 * (n - 21)
12+
return 21 - n

Solutions/warmup-1/makes10.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Given 2 ints, a and b, return True if one if them is 10 or if their sum is 10.
2+
3+
# makes10(9, 10) → True
4+
# makes10(9, 9) → False
5+
# makes10(1, 9) → True
6+
7+
8+
def makes10(a, b):
9+
return (a == 10 or b == 10) or (a + b == 10)

Solutions/warmup-1/parrot_trouble.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# We have a loud talking parrot. The "hour" parameter
2+
# is the current hour time in the range 0..23.
3+
# We are in trouble if the parrot is talking and the
4+
# hour is before 7 or after 20.
5+
# Return True if we are in trouble.
6+
7+
# parrot_trouble(True, 6) → True
8+
# parrot_trouble(True, 7) → False
9+
# parrot_trouble(False, 6) → False
10+
11+
12+
def parrot_trouble(talking, hour):
13+
return talking and (hour < 7 or hour > 20)

0 commit comments

Comments
 (0)