Skip to content

Commit e7312f7

Browse files
authored
upload pset2
1 parent bd11b66 commit e7312f7

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

pset2/camel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def main():
2+
camel = input('Name: ')
3+
print('Name: ',end='')
4+
snake = convert(camel)
5+
print('')
6+
7+
def convert(camel):
8+
for character in camel:
9+
if character.isupper():
10+
print('_' + character.lower(), end='')
11+
else:
12+
print(character, end='')
13+
14+
main()

pset2/coke.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cost = 50
2+
due = cost
3+
while due > 0:
4+
print('Amount Due: '+str(due))
5+
coin = int(input('Insert Coin: '))
6+
if coin==25 or coin==10 or coin==5:
7+
due -= coin
8+
if due < 0:
9+
due = -due
10+
11+
print('Change owed: '+str(due))

pset2/nutrition.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
food = {
2+
'apple':'130',
3+
'avocado':'50',
4+
'banana':'110',
5+
'cantaloupe':'50',
6+
'grapefruit':'60',
7+
'grapes':'90',
8+
'honeydew':'50',
9+
'kiwifruit':'90',
10+
'lemon':'15',
11+
'lime':'20',
12+
'nectarine':'60',
13+
'orange':'80',
14+
'peach':'60',
15+
'pear':'100',
16+
'pineapple':'50',
17+
'plums':'70',
18+
'strawberries':'50',
19+
'sweet cherries': '100',
20+
'tangerine':'50',
21+
'watermelon':'80'
22+
}
23+
24+
fruit = input('Item: ').lower()
25+
if fruit in food:
26+
print('Calories:',food[fruit])

pset2/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
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+
40+
main()

pset2/twttr.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
vowels = ['a','e','i','o','u', 'A','E','I','O','U']
2+
inpt= input('Input: ')
3+
print('Output: ', end='')
4+
5+
for letter in inpt:
6+
if letter in vowels:
7+
pass
8+
else:
9+
print(letter, end='')
10+
print('')

0 commit comments

Comments
 (0)