Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTennyson authored Jan 21, 2020
1 parent c99083e commit 6a33f49
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
15 changes: 15 additions & 0 deletions week8tut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# q1
# the following program takes in a users number
# the number is set as a key and is value is the result of the key multiplied by itself
dict_1 = {2: ''}
num = dict_1.keys()
num2 = num * num
dict_1[2] = num2

print(dict_1)






19 changes: 19 additions & 0 deletions week8tut2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# the following program will combine to two dictionaries into one

dict_a = {'a': 100, 'b': 200, 'c': 300}
dict_b = {'a': 300, 'b': 200, 'd': 400}
dict_c = {}

for key in dict_a:
dict_c[key] = dict_a[key]


for key in dict_b:
if key in dict_a.keys():
dict_c[key] += dict_b[key]
else:
dict_c[key] = dict_b[key]

print(dict_c)


10 changes: 10 additions & 0 deletions week8tut3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
dict_b = {'1':'one', '2':'two', '3':'three', '4':'four', '5':'five', '6':'six', '7':'seven','8':'eight', '9':'nine', '0':'zer0'}

num = input('enter a number\n')
dict_keys = dict_b.keys()

for char in num:
if char in dict_keys:
print(dict_b[char],end='')
else:
print('you must enter a number')
34 changes: 34 additions & 0 deletions week8tut4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# the following program prompts a user to enter a country and its capital
# takes a users input and puts it in a dictionary
# and iterates this again

# function checks if the user has entered yes or no, repeating the program
def check_input(input):
if input == 'y' or input == 'n':
return True
return False

capitals = {}

country_str = input('enter a country\n')
country_cap = input('enter the capital of the country you just entered\n')
capitals[country_str] = country_cap

# here, the loop variable. holding the user decision is passed to the function
loop = input('do you want to enter another country (y/n) : ')
while(check_input(loop) == False):
loop = input('do ou want to enter another country(y/n) :')

if loop == 'n':
break

# list is made to hold the country and capital
value_key_list = []
for key, val in capitals.items():
value_key_list.append((key,val))
value_key_list.sort()

for val, key in value_key_list:
print(key, ': ', val)


15 changes: 15 additions & 0 deletions week8ut5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# this program checks if a sentence entered is a heterogram or not
def heterogram(sentence):
sentence_list = list(sentence)

# ord function returns ascii version of character
alphabet = [ch for ch in sentence_list if(ord(ch) >= ord('a') and ord(ch) <= ord('z'))]
sentence_set = set(sentence_list)

if len(sentence_set) == len(alphabet):
print('yes, your word is a hectogram')
else:
print('no, your word is not a hectogram')


print('enter a word that does not use a letter more than twice(hectogram)')

0 comments on commit 6a33f49

Please sign in to comment.