forked from tdjohner/Python_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1TJb.py
More file actions
53 lines (33 loc) · 1.33 KB
/
Lab1TJb.py
File metadata and controls
53 lines (33 loc) · 1.33 KB
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
#-------------------------------------------------------------------------
# Lab1TJ.py
#-------------------------------------------------------------------------
# Teagan Johner
# Program name: Percentage of Odd Integers
#-------------------------------------------------------------------------
# count_odd() goes through each number in a given list and counts how many of them are odd
# syntax: count_odd([list of numbers here])
# ex.
# count_odd([1, 2, 3, 4])
# arguments: listOfNumbers
# returns: the total of odd numbers in listOfNumbers
def count_odd(listOfNumbers):
tally = 0
for i in range(len(listOfNumbers)):
if listOfNumbers[i] % 2 == 1:
tally += 1
return tally
# percent_odd gives the percentage of numbers in a list that are odd
# syntax: percent_odd([list of numbers here])
# ex.
# percent_odd([1, 2, 3, 4])
# arguments: listOfNumbers
# returns: the percentage of odd numbers in the list
def percent_odd(listOfNumbers):
oddNum = count_odd(listOfNumbers)
tally = 0
for i in range(len(listOfNumbers)):
tally += 1
if oddNum != 0:
return tally / oddNum
else:
return 0