Skip to content

Commit 2cef785

Browse files
authored
uploading pset5
1 parent dacdff5 commit 2cef785

File tree

8 files changed

+200
-0
lines changed

8 files changed

+200
-0
lines changed

pset5/bank/bank.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def main():
2+
greet= input('Greeting: ')
3+
fine = value(greet)
4+
print('$'+str(fine))
5+
6+
def value(greeting):
7+
8+
greeting = greeting.lower().strip()
9+
10+
if 'hello' in greeting:
11+
return(0)
12+
elif 'h' in greeting[0]:
13+
return(20)
14+
else:
15+
return(10)
16+
17+
18+
if __name__ == "__main__":
19+
main()
20+
21+
22+
23+

pset5/bank/test_bank.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from bank import value
2+
3+
def test_hello():
4+
assert value('hello') == 0
5+
assert value('hello, world') == 0
6+
7+
8+
def test_h():
9+
assert value('hey') == 20
10+
assert value('how ya doin') == 20
11+
assert value('hola habibi') == 20
12+
assert value('hel, lo') == 20
13+
14+
def test_noH():
15+
assert value('whats up, buddy') == 100
16+
assert value('what the he!@') == 100
17+
18+
def test_capital():
19+
assert value('HELLO') == 0
20+
assert value('Hey') == 20

pset5/fuel/fuel.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def main():
2+
while True:
3+
try:
4+
percentage = convert(input())
5+
except:
6+
pass
7+
else:
8+
break
9+
print(gauge(percentage))
10+
11+
12+
def convert(fraction):
13+
x,y = fraction.split('/')
14+
x, y=int(x), int(y)
15+
if y==0:
16+
raise ZeroDivisionError
17+
elif y<x:
18+
raise ValueError
19+
return int(round((x/y)*100))
20+
21+
def gauge(percent):
22+
if percent <= 1:
23+
return'E'
24+
elif percent >= 99:
25+
return'F'
26+
else:
27+
return str(percent)
28+
29+
30+
if __name__ == "__main__":
31+
main()
32+
33+
34+
35+
36+
37+

pset5/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+
4+
def test_input():
5+
assert convert('1/2') == 50
6+
assert convert('1/1') == 100
7+
assert convert('0/10') == 0
8+
9+
def test_errors():
10+
with pytest.raises(ZeroDivisionError):
11+
convert('2/0')
12+
with pytest.raises(ValueError):
13+
convert('3/2')
14+
15+
def test_output():
16+
assert gauge(1) == 'E'
17+
assert gauge(100) == 'F'
18+
assert gauge(50) == '50%'

pset5/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+
plate = input("Plate: ")
3+
if is_valid(plate):
4+
print("Valid")
5+
else:
6+
print("Invalid")
7+
8+
9+
def is_valid(s):
10+
# check for length
11+
if len(s)>6 or len(s)<2:
12+
return False
13+
# check alphanumeric
14+
elif not s.isalnum():
15+
return False
16+
# check first 2 elements are alphabets
17+
elif not (s[0].isalpha() and s[1].isalpha()):
18+
return False
19+
#find first number
20+
first_num=len(s)-1
21+
for character in s:
22+
if character.isnumeric():
23+
# check if first number is zero bugged
24+
#if character=='0':
25+
# return False
26+
first_num = s.index(character)
27+
break
28+
# check if there is no alphabet after first num
29+
for character in s:
30+
if s.index(character)<= first_num:
31+
pass
32+
else:
33+
if character.isalpha():
34+
return False
35+
#all conditions satisfied
36+
return True
37+
38+
39+
if __name__ == '__main':
40+
main()

pset5/plates/test_plates.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from plates import is_valid
2+
3+
def test_length():
4+
assert is_valid('a') == False
5+
assert is_valid('ipho123') == False
6+
assert is_valid('van123') == True
7+
8+
def test_startLetters():
9+
assert is_valid('ab') == True
10+
assert is_valid('a123') == False
11+
assert is_valid('z2') == False
12+
13+
def test_numbersLast():
14+
assert is_valid('ama2on') == False
15+
assert is_valid('g00gle') == False
16+
assert is_valid('ll001') == False
17+
assert is_valid('ll100') == True
18+
19+
def test_invalidChar():
20+
assert is_valid('ir0.1') == False
21+
assert is_valid('gt!') == False
22+
assert is_valid('wall e') == False
23+

pset5/twttr/test_twttr.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from twttr import shorten
2+
3+
def test_nonAlpha():
4+
assert shorten('$twenty-five') == '$twnty-fv'
5+
assert shorten('25 dollars') == '25 dllrs'
6+
assert shorten('$25.00') == '$25.00'
7+
8+
def test_consonants():
9+
assert shorten('tstst') == 'tstst'
10+
assert shorten('lgbtq') == 'lgbtq'
11+
12+
def test_vowels():
13+
assert shorten('aie') == ''
14+
assert shorten('ou') == ''
15+
16+
def test_capital():
17+
assert shorten('APPLE') == 'PPL'
18+

pset5/twttr/twttr.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def main():
2+
inpt= input('Input: ')
3+
devowelised_text = shorten(inpt)
4+
print('Output:', devowelised_text)
5+
6+
def shorten(word):
7+
# vowels = ['a','e','i','o','u','A','E','I','O','U']
8+
# the below line cause a bug
9+
vowels = ['a','e','i','o','u',]
10+
for vowel in vowels:
11+
if vowel in word:
12+
word = word.replace(vowel, '')
13+
return word
14+
if __name__ == "__main__":
15+
main()
16+
17+
18+
19+
20+
21+

0 commit comments

Comments
 (0)