Skip to content

Commit 5ac8839

Browse files
authored
Add files via upload
1 parent 2962e6f commit 5ac8839

16 files changed

+182
-0
lines changed
1.12 KB
Binary file not shown.
4.97 KB
Binary file not shown.
Binary file not shown.
972 Bytes
Binary file not shown.

Problem_Set_5/test_bank/bank.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def main():
2+
#Get input.
3+
greeting=input("Greeting: ")
4+
ret_val=value(greeting)
5+
print("$"+ret_val)
6+
#Define value fn.
7+
def value(greeting):
8+
if(greeting.lower().strip()== 'hello'or greeting.strip().lower().startswith('hello')):
9+
return(0)
10+
elif(greeting.strip().lower().startswith('h')):
11+
return(20)
12+
else:
13+
return(100)
14+
15+
if __name__=="__main__":
16+
main()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from bank import value
2+
def main():
3+
pass
4+
#Test if str starts with "hello".
5+
def test_hello():
6+
assert value('hello')==0
7+
assert value('HELLO')==0
8+
#Test if str starts with "h"(but not "hello").
9+
def test_h():
10+
assert value('hey')==20
11+
assert value('HeY')==20
12+
#Test for other str.
13+
def test_str():
14+
assert value("sup")==100
15+
assert value("SUP")==100
1.49 KB
Binary file not shown.
Binary file not shown.

Problem_Set_5/test_fuel/fuel.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def main():
2+
userip=input("Fraction: ")
3+
per=convert(userip)
4+
ind=gauge(per)
5+
print(ind)
6+
7+
8+
def convert(userip):
9+
while True:
10+
try:
11+
x,y=userip.split(sep='/')
12+
x=int (x)
13+
y=int (y)
14+
p=x/y
15+
if p<=1:return int(p*100)
16+
else:userip=input("Fraction: ")
17+
except(ValueError,ZeroDivisionError):
18+
raise
19+
20+
def gauge(per):
21+
if per<=1:return("E")
22+
elif 99<=per<=100:return("F")
23+
elif 1<per<99:return str(per) +"%"
24+
25+
26+
if __name__ == "__main__":
27+
main()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from fuel import convert, gauge
2+
import pytest
3+
#Test ZeroDivisionError
4+
def test_zeroDivEr():
5+
with pytest.raises(ZeroDivisionError):
6+
convert('1/0')
7+
8+
#Test ValueError
9+
def test_val():
10+
with pytest.raises(ValueError):
11+
convert('cat/rat')
12+
13+
#Test Correct i/p.
14+
15+
def test_ip():
16+
assert convert('1/2')==50 and gauge(50)=='50%'
17+
assert convert('1/100')==1 and gauge(1)=='E'
18+
assert convert('99/100')==99 and gauge(99)=='F'

0 commit comments

Comments
 (0)