Skip to content

Instantly share code, notes, and snippets.

@bukandu1
Last active July 8, 2019 19:17
Show Gist options
  • Save bukandu1/fbcceed4804827a62289f5d6c9968ea4 to your computer and use it in GitHub Desktop.
Save bukandu1/fbcceed4804827a62289f5d6c9968ea4 to your computer and use it in GitHub Desktop.
HB_PreWork_ScribbleAndNotes created by BeverlyUkandu - https://repl.it/@BeverlyUkandu/HBPreWorkScribbleAndNotes
def add_fruit(inventory, fruit, quantity=0):
return
# Make these tests work...
new_inventory = {}
add_fruit(new_inventory, "strawberries", 10)
test("strawberries" in new_inventory)
test(new_inventory["strawberries"] == 10)
add_fruit(new_inventory, "strawberries", 25)
test(new_inventory["strawberries"] == 35)
#Write a program that reads a string and returns a table of the letters of the alphabet in alphabetical order which occur in the string together with the number of times each letter occurs. Case should be ignored. A sample output of the program when the user enters the data “ThiS is String with Upper and lower case Letters”, would look this this:
def alpha(string):
#iterate through string and store each letter to key
alpha_dict = {}
for letter in string.lower():
if letter.isalpha():
alpha_dict[letter] = alpha_dict.get(letter,0) + 1
#sort the keys into alphabetical order using a list
alpha_keys = list(alpha_dict.keys())
alpha_key = alpha_keys.sort()
#print key then key item
for key in alpha_keys:
print(key,alpha_dict[key])
alpha("Four score and seven years ago!")
def print_n(s, n):
if n <= 0:
return
print(s)
print_n(s, n-1)
def print_n_while(s,n):
while n > 0:
print(s)
n -= 1
print_n("hello", 5)
print_n_while("hi", 5)
#person={'first':1, 'second':3}
#print('{p[first]} {p[second]:{align}{width}}'.format(p=person, align='^', width='10'))
name = input("Hello. What's your name? ")
yes = input("What's the name of someone you'd like to go on an adventure with?: ")
not not True or False and not True
def is_triangle(int1, int2, int3):
if int1 > (int2 + int3) or int2 > (int3 or int2) or int3 > (int1 or int2):
return "No"
return "Yes"
i1 = input("Triangle Side 1: ")
i2 = input("Triangle Side 2: ")
i3 = input("Triangle Side 3: ")
print(is_triangle(i1 ,i2 ,i3))
print(is_triangle(5 ,3 ,2))
print(is_triangle(1 ,3 ,5))
print(is_triangle(1 ,1 ,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment