-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_3_4.py
71 lines (66 loc) · 1.44 KB
/
1_3_4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
def food_id(food):
Returns categorization of food
food is a string
returns a string of categories
# The data
fruits = ['apple', 'banana', 'orange']
citrus = ['orange']
starchy = ['banana', 'potato']
# Check the category and report
if food in fruits:
if food in citrus:
return 'Citrus, Fruit'
else:
return 'NOT Citrus, Fruit'
else:
if food in starchy:
return 'Starchy, NOT Fruit'
else:
return 'NOT Starchy, NOT Fruit'
def food_id_test():
# Unit test for food_id
# returns True if good, returns False and prints error if not good
works = True
if food_id('orange') != 'Citrus, Fruit':
works = False
print('orange bug in food id()')
if food_id('banana') != 'NOT Citrus, Fruit':
works = False
print('banana bug in food_id()')
if food_id('potato') != 'Starchy, NOT Fruit':
works = False
print('potato bug in food_id()')
if food_id('donut') != 'NOT Starchy, NOT Fruit':
works = False
print('donut bug in food_id()')
# Add tests so that all lines of code are visited during test
if works:
print('food_id passed all tests')
return works
food_id_test()
'''
def f(x):
if int(x) == x:
if x%2 == 0:
if x%3 == 0:
print(x, 'is a multiple of 6')
else:
print(x, 'is even')
else:
print(x, 'is odd')
else:
print(x, 'is not an integer')
return x
f(18)
f(8)
f(9)
f(9.2)
while True:
number = input("Pick a number: ")
if number == 'stop':
break
else:
number = eval(number)
f(number)
continue