-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c99083e
commit 6a33f49
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)') |