Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
def main():
greeting = input("Greeting:\t\t")
print(value(f"${greeting}"))
def value(greeting: str) -> str:
greeting = greeting.lower().strip()
if greeting.startswith("hello"):
return 0
elif greeting.startswith("h"):
return 20
else:
return 100
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,77 @@
from bank import value
def main():
test_lower()
test_upper()
test_title_case()
test_mixed_case()
test_zero()
test_twenty()
test_empty()
test_hundred()
test_containing_hello()
def test_lower():
assert value('hello') == 0
assert value('hey') == 20
assert value('banana') == 100
def test_upper():
assert value('HELLO') == 0
assert value('HEY') == 20
assert value('BANANA') == 100
def test_title_case():
assert value('Hello') == 0
assert value('Hey') == 20
assert value('Banana') == 100
def test_mixed_case():
assert value('Hello') == 0
assert value('Hey') == 20
assert value('Banana') == 100
def test_zero():
assert value('Hello') == 0
assert value('hello') == 0
assert value('HELLO') == 0
assert value('HeLlO') == 0
assert value('hElLo') == 0
def test_twenty():
assert value('Hey') == 20
assert value('hey') == 20
assert value('HEY') == 20
assert value('HeY') == 20
assert value('hEy') == 20
assert value('h') == 20
assert value('h20') == 20
def test_empty():
assert value('') == 100
def test_hundred():
assert value('Banana') == 100
assert value('banana') == 100
assert value('BANANA') == 100
assert value('12345678') == 100
assert value('nothello') == 100
def test_containing_hello():
assert value('aHello') == 100
assert value('ahello') == 100
assert value('aHELLO') == 100
assert value('aHeLlO') == 100
assert value('ahElLo') == 100
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,35 @@
def main():
while True:
fuel = input("Fraction:\t\t")
try:
result = convert(fuel)
break
except (ValueError, ZeroDivisionError):
continue
print(gauge(result))
def convert(fraction: str) -> int:
try:
x, y = map(int, fraction.split('/'))
except (ValueError, TypeError):
raise ValueError
if x > y:
raise ValueError
if y == 0:
raise ZeroDivisionError
return int(round(x / y*100, 0))
def gauge(percentage):
if percentage <= 1:
return "E"
elif percentage >= 99:
return "F"
else:
return f"{percentage}%"
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,41 @@
from fuel import convert, gauge
def main():
test_convert()
test_gauge()
test_value_error()
test_zero_division_error()
def test_convert():
assert convert("0/4") == 0
assert convert("1/4") == 25
assert convert("4/4") == 100
def test_value_error():
try:
convert("5/4")
except ValueError:
pass
else:
raise Exception("ValueError not raised with y>x")
def test_zero_division_error():
try:
convert("5/0")
except ZeroDivisionError:
pass
else:
raise Exception("ZeroDivisionError not raised with y = 0")
def test_gauge():
assert gauge(100) == 'F'
assert gauge(99) == 'F'
assert gauge(0) == 'E'
assert gauge(1) == 'E'
assert gauge(27) == '27%'
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,39 @@
import re
def main():
plate = input("Plate: ")
if is_valid(plate):
print("Valid")
else:
print("Invalid")
def is_valid(s):
if len(s) < 2 or len(s) > 6:
return False
return re.match(r"^[A-Z]{2,}([1-9]\d+)?(?![A-Z])$", s) is not None
def loopy_is_valid(s):
length = 0
has_digits = False
for n, c in enumerate(s):
if n > 6:
return False
if not c.isalnum():
return False
if n < 2 and not c.isalpha():
return False
if c.isdigit():
if not has_digits and c == '0':
return False
has_digits = True
elif has_digits:
return False
length += 1
return length >= 2
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,39 @@
from plates import is_valid
def main():
test_incipit()
test_length()
test_digits()
test_forbidden_characters()
def test_incipit():
assert is_valid('11AA11') == False
assert is_valid('11AA') == False
assert is_valid('1AA2') == False
assert is_valid('2AAP') == False
assert is_valid('A1111') == False
assert is_valid('AA1111') == True
def test_length():
assert is_valid('') == False
assert is_valid('A') == False
assert is_valid('AAAAAA111111') == False
def test_digits():
assert is_valid('AA111A') == False
assert is_valid('AA0111') == False
def test_forbidden_characters():
assert is_valid('AA1.1') == False
assert is_valid('AA1,1') == False
assert is_valid('AA1 1') == False
assert is_valid('AA11!') == False
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,33 @@
from twttr import shorten
def main():
test_uppercase()
test_lowercase()
test_null()
test_digits()
test_punctuation()
def test_uppercase():
assert shorten('TWITTER') == 'TWTTR'
def test_lowercase():
assert shorten('twitter') == 'twttr'
def test_null():
assert shorten('') == ''
def test_digits():
assert shorten('abc123') == 'bc123'
def test_punctuation():
assert shorten('abc,') == 'bc,'
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,16 @@
def main():
tweet = input("Input: \t\t")
result = shorten(tweet)
print(f"Output: {result}")
def shorten(word: str) -> str:
result = ''
for c in word:
if c.lower() not in ('a', 'e', 'i', 'o', 'u'):
result += c
return result
if __name__ == "__main__":
main()