From 6a33f49dae2daccb6c9bf8b0814354effcb1b85d Mon Sep 17 00:00:00 2001 From: MichaelTennyson <55544189+MichaelTennyson@users.noreply.github.com> Date: Tue, 21 Jan 2020 17:57:20 +0000 Subject: [PATCH] Add files via upload --- week8tut.py | 15 +++++++++++++++ week8tut2.py | 19 +++++++++++++++++++ week8tut3.py | 10 ++++++++++ week8tut4.py | 34 ++++++++++++++++++++++++++++++++++ week8ut5.py | 15 +++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 week8tut.py create mode 100644 week8tut2.py create mode 100644 week8tut3.py create mode 100644 week8tut4.py create mode 100644 week8ut5.py diff --git a/week8tut.py b/week8tut.py new file mode 100644 index 0000000..84a1459 --- /dev/null +++ b/week8tut.py @@ -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) + + + + + + diff --git a/week8tut2.py b/week8tut2.py new file mode 100644 index 0000000..8741d59 --- /dev/null +++ b/week8tut2.py @@ -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) + + diff --git a/week8tut3.py b/week8tut3.py new file mode 100644 index 0000000..5250d58 --- /dev/null +++ b/week8tut3.py @@ -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') \ No newline at end of file diff --git a/week8tut4.py b/week8tut4.py new file mode 100644 index 0000000..a47df03 --- /dev/null +++ b/week8tut4.py @@ -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) + + diff --git a/week8ut5.py b/week8ut5.py new file mode 100644 index 0000000..7b48b2c --- /dev/null +++ b/week8ut5.py @@ -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)') \ No newline at end of file