-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectronics.py
More file actions
68 lines (48 loc) · 1.26 KB
/
Copy pathelectronics.py
File metadata and controls
68 lines (48 loc) · 1.26 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def find_letter(input: str) -> str:
input = float(input)
mega = input / 1E6
kilo = input / 1000
if mega >= 1:
letter = "M"
elif kilo >= 1:
letter = "k"
else:
letter = "R"
return letter
def find_ohm(input: str, letter: str) -> str:
suffix = {
"M": 1E6,
"k": 1E3,
"R": 1
}
input = float(input)
start = input / suffix[letter]
if 1000 > start >= 10:
first = start / 10
first = int(first)
first = str(first)
second = start /10
second = second % 1
second = round(second, 1)
second = second * 10
second = int(second)
second = str(second)
return first + second + letter
elif 10 > start > 1:
first = int(start)
first = str(first)
second = start % 1
second = round(second, 1)
second = second * 10
second = int(second)
second = str(second)
if second == "0":
second = ""
return first + letter + second
elif start == 1:
start = int(start)
start = str(start)
return start + letter
def resistance_converter(input: str) -> str:
suffix = find_letter(input)
return find_ohm(input, suffix)