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.
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()

Problem_Set_5/test_bank/test_bank.py

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
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()

Problem_Set_5/test_fuel/test_fuel.py

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'
Binary file not shown.
Binary file not shown.

Problem_Set_5/test_plates/plates.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def main():
2+
#Get input.
3+
plate = input("Plate: ")
4+
#Print output based in is_valid fn.
5+
if is_valid(plate):
6+
print("Valid")
7+
else:
8+
print("Invalid")
9+
#Define is_valid.
10+
def is_valid(s):
11+
#Check for length.
12+
if len(s)>6 or len(s)<2:
13+
return False
14+
#Check if first two digits are alphabet.
15+
if s[0].isalpha()==False or s[1].isalpha()==False:
16+
return False
17+
#Check for space,period and punctuations.
18+
if s.isalnum()==False:
19+
return False
20+
for i in s:
21+
if i==" ":
22+
return False
23+
#Check if first digit occuring is 0.
24+
for i in s:
25+
if i.isdigit()==True:
26+
if i=='0':
27+
return False
28+
else:
29+
break
30+
#Check if digits are occuring in middle.
31+
for i in range(len(s)):
32+
if s[i].isdigit()==True:
33+
if not s[i:].isdigit():
34+
return False
35+
#True if all above conditions are satisfied.
36+
return True
37+
38+
39+
if __name__=="__main__":
40+
main()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from plates import is_valid
2+
def main():
3+
pass
4+
#Plates can contain max of 6 char and min of 2 char.
5+
def test_min_max_char():
6+
assert is_valid('XX')==True
7+
assert is_valid('XXXXXX')==True
8+
assert is_valid('X')==False
9+
assert is_valid('XXXXXXXXXX')==False
10+
11+
#Plates should start with at least two letters.
12+
def test_2lttr():
13+
assert is_valid('XX')==True
14+
assert is_valid('X1')==False
15+
assert is_valid('1X')==False
16+
assert is_valid('11')==False
17+
18+
#Numbers cannot be used in the middle of a plate; they must come at the end.
19+
def test_num_in_middle():
20+
assert is_valid('XXX222')==True
21+
assert is_valid('XXX22X')==False
22+
23+
#First num used cannot be zero.
24+
def test_num_zero():
25+
assert is_valid('XX10')==True
26+
assert is_valid('XX01')==False
27+
28+
#No periods, spaces, or punctuation marks are allowed.
29+
def test_spchar():
30+
assert is_valid('XX3.14')==False
31+
assert is_valid('AB3&14')==False
32+
assert is_valid('VE3 14')==False
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from twttr import shorten
2+
3+
def main():
4+
pass
5+
#Test for case.
6+
def test_case():
7+
assert shorten('twitter')=='twttr'
8+
assert shorten('TWITTER')=='TWTTR'
9+
assert shorten('TwTteR')=='TwTtR'
10+
#Test numbers.
11+
def test_num():
12+
assert shorten('1234')=='1234'
13+
#Test special characters.
14+
def test_spchar():
15+
assert shorten('?.,!@')=='?.,!@'

Problem_Set_5/test_twttr/twttr.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def main():
2+
#Get input.
3+
userip=input("Input: ")
4+
#Get message without vowels from shorten fn.
5+
word=shorten(userip)
6+
#Print output.
7+
print("Output: "+word)
8+
#Shoeten definition.
9+
def shorten(word):
10+
new_word=""
11+
#Get new word with all vowels removed.
12+
for i in word:
13+
if not (i=='a' or i=='A'or i=='e' or i=='E'or i=='o' or i=='O'or i=='i'or i=='I'or i=='u' or i=='U'):
14+
new_word+=i
15+
#Return the word.
16+
return(new_word)
17+
18+
if __name__=="__main__":
19+
main()

0 commit comments

Comments
 (0)