Preparing git repo for final project
This commit is contained in:
16
problems/pset2/camel/camel.py
Normal file
16
problems/pset2/camel/camel.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def main():
|
||||
camel_string = input("camelCase:\t\t")
|
||||
print(f"snake_case:\t\t{convert_to_snake_case(camel_string)}")
|
||||
|
||||
|
||||
def convert_to_snake_case(s: str):
|
||||
result = ''
|
||||
for char in s:
|
||||
if char == char.upper():
|
||||
result += '_'
|
||||
result += char.lower()
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
15
problems/pset2/coke/coke.py
Normal file
15
problems/pset2/coke/coke.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def main():
|
||||
total_coins = 0
|
||||
while total_coins < 50:
|
||||
print(f"Amount Due: {50 - total_coins}")
|
||||
new_coin = input("Insert coin:\t\t")
|
||||
if new_coin not in ('5', '10', '25'):
|
||||
new_coin = 0
|
||||
else:
|
||||
new_coin = int(new_coin)
|
||||
total_coins += new_coin
|
||||
print(f"Change Owed: {total_coins - 50}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
14
problems/pset2/nutrition/nutrition.py
Normal file
14
problems/pset2/nutrition/nutrition.py
Normal file
@@ -0,0 +1,14 @@
|
||||
fruits = {'apple': '130', 'avocado': '50', 'banana': '110', 'cantaloupe': '50',
|
||||
'grapefruit': '60', 'grapes': '90', 'honeydew melon': '50', 'kiwifruit': '90', 'lemon': '15', 'lime': '20',
|
||||
'nectarine': '60', 'orange': '80', 'peach': '60', 'pear': '100', 'pineapple': '50', 'plums': '70', 'strawberries': '50',
|
||||
'sweet cherries': '100', 'tangerine': '50', 'watermelon': '80'}
|
||||
|
||||
|
||||
def main():
|
||||
fruit = input("Item:\t\t").lower()
|
||||
if fruit in fruits:
|
||||
print(f"Calories:\t\t{fruits[fruit]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
39
problems/pset2/plates/plates.py
Normal file
39
problems/pset2/plates/plates.py
Normal 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)
|
||||
|
||||
|
||||
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()
|
11
problems/pset2/twttr/twttr.py
Normal file
11
problems/pset2/twttr/twttr.py
Normal file
@@ -0,0 +1,11 @@
|
||||
def main():
|
||||
tweet = input("Input: \t\t")
|
||||
result = ''
|
||||
for c in tweet:
|
||||
if c.lower() not in ('a', 'e', 'i', 'o', 'u'):
|
||||
result += c
|
||||
print(f"Output: {result}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user