-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinter_errors.py
51 lines (32 loc) · 1.55 KB
/
Printer_errors.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
'''
Printer Errors :
In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from a to m.
The colors used by the printer are recorded in a control string. For example a "good" control string would be aaabbbbhaijjjm meaning that the printer used three times color a, four times color b, then one time color a...
Sometimes there are problems: lack of colors, technical malfunction and a "bad" control string is produced e.g. aaaxbbbbyyhwawiwjjjwwm.
You have to write a function printer_error which given a string will output the error rate of the printer as a string representing a rational whose numerator is the number of errors and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.
The string has a length greater or equal to one and contains only letters from ato z.
#Examples:
s="aaabbbbhaijjjm"
error_printer(s) => "0/14"
s="aaaxbbbbyyhwawiwjjjwwm"
error_printer(s) => "8/22"
'''
def printer_error(s):
denom = len(s)
colours = "abcdefghijklm"
count = 0
for letter in s:
for colour in colours:
if letter == colour:
count += 1
numer = denom - count
return str(numer) + "/" + str(denom)
def printer_errors(s):
denom = len(s)
numer = 0
for letter in s:
if s > m
numer += 1
return str(numer) + "/" + str(denom)
def printer_errors(s):
return "{} / {}".format(len[for letter in s if s > m] ,len(s))