-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPT1.py
More file actions
28 lines (22 loc) · 928 Bytes
/
PT1.py
File metadata and controls
28 lines (22 loc) · 928 Bytes
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
#!/usr/bin/env python3
# Author: Harrison Morrow
# Name: Programming Task 1
# Purpose: Given a list of digits determine the integer that it represents
import typing
def digit_list_reader(digit_list: list[int]) -> int:
"""
Takes a list of decimal digits (digit list)
Returns the integer the list represents
"""
# Create our output
output = 0
# Reverse our list so we can work through each element from lowest decimal value to highest decimal value
reversed_digit_list = list(reversed(digit_list))
# Use a 'for' loop to loop over all positions in our list
for i in range(len(reversed_digit_list)):
current_digit = reversed_digit_list[i] # Get value of current digit
output += current_digit * 10 ** i # Add that value to our output
# Tell our caller the result of our calculation
return output
if __name__ == '__main__':
print(digit_list_reader([8,3,5,1]))