File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 11
11
pass
12
12
13
13
p = round (f * 100 )
14
- if p == 100 :
14
+ if p == 99 :
15
15
print ("F" )
16
16
elif p <= 1 :
17
17
print ("E" )
Original file line number Diff line number Diff line change
1
+ def main ():
2
+ fuel = input ("Fraction: " )
3
+ percentage = convert (fuel )
4
+ print (gauge (percentage ))
5
+
6
+
7
+ def convert (fraction ):
8
+ while True :
9
+ try :
10
+ x , y = fraction .split ("/" )
11
+ new_x = int (x )
12
+ new_y = int (y )
13
+ f = new_x / new_y
14
+ if f <= 1 :
15
+ p = round (f * 100 )
16
+ return p
17
+ else :
18
+ fraction = input ("Fraction: " )
19
+ pass
20
+ except (ValueError , ZeroDivisionError ):
21
+ raise
22
+
23
+
24
+ def gauge (percentage ):
25
+ if percentage == 99 :
26
+ return "F"
27
+ elif percentage <= 1 :
28
+ return "E"
29
+ else :
30
+ return f"{ percentage } %"
31
+
32
+
33
+ if __name__ == "__main__" :
34
+ main ()
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from fuel import convert , gauge
3
+
4
+ def main ():
5
+ test_correct_input ()
6
+ test_zero_division ()
7
+ test_value_error ()
8
+
9
+
10
+ def test_correct_input ():
11
+ # Test valid inputs and their expected outputs
12
+ assert convert ('1/4' ) == 25 and gauge (25 ) == '25%'
13
+ assert convert ('1/100' ) == 1 and gauge (1 ) == 'E'
14
+ assert convert ('99/100' ) == 99 and gauge (99 ) == 'F'
15
+
16
+ def test_zero_division ():
17
+ # Test division by zero
18
+ with pytest .raises (ZeroDivisionError ):
19
+ convert ('1/0' )
20
+
21
+ def test_value_error ():
22
+ with pytest .raises (ValueError ):
23
+ convert ('cat/dog' )
24
+
25
+ if __name__ == "__main__" :
26
+ main ()
You can’t perform that action at this time.
0 commit comments