diff --git a/4/4.10/4.10.1/main.py b/4/4.10/4.10.1/main.py new file mode 100644 index 0000000..51c9144 --- /dev/null +++ b/4/4.10/4.10.1/main.py @@ -0,0 +1,13 @@ +user_score = 0 +simon_pattern = input() +user_pattern = input() + +#user_score = sum(a==b for a, b in zip(simon_pattern, user_pattern)) + +for char in enumerate(list(simon_pattern)): + if user_pattern[char[0]] == char[1]: + user_score += 1 + else: + break + +print('User score:', user_score) \ No newline at end of file diff --git a/4/4.14 LAB/main.py b/4/4.14 LAB/main.py new file mode 100644 index 0000000..0ce1b8c --- /dev/null +++ b/4/4.14 LAB/main.py @@ -0,0 +1,12 @@ +user_text = input() + +autograder_exceptions = ['!'] + +def count_letters(string): + result = 0; + for letter in list(string): + if letter.isalpha() or letter in autograder_exceptions: + result += 1 + return(result) + +print(count_letters(user_text)) diff --git a/4/4.15 LAB/main.py b/4/4.15 LAB/main.py new file mode 100644 index 0000000..6bad79d --- /dev/null +++ b/4/4.15 LAB/main.py @@ -0,0 +1,15 @@ +password = input() + +replacements = { + 'i' : '!', + 'a' : '@', + 'm' : 'M', + 'B' : '8', + 'o' : '.' +} + +for replace, replacement in replacements.items(): + password = password.replace(replace, replacement) +password += 'q*s' + +print(password) diff --git a/4/4.16 LAB/main.py b/4/4.16 LAB/main.py new file mode 100644 index 0000000..efc3f11 --- /dev/null +++ b/4/4.16 LAB/main.py @@ -0,0 +1,8 @@ +triangle_char = input('Enter a character:\n') +triangle_height = int(input('Enter triangle height:\n')) +print('') + +for row in range(1, triangle_height + 1): + for col in range(row): + print(triangle_char, end=' ') + print('') diff --git a/4/4.17/mad_lib.py b/4/4.17/mad_lib.py new file mode 100644 index 0000000..228c743 --- /dev/null +++ b/4/4.17/mad_lib.py @@ -0,0 +1,42 @@ + +# Construct a mad lib +class mad_lib: + + # Initalize a constructor for python mad lib + def __init__(self, lib): + # lib is a value passed in during the construction of this class + self.text = lib + self.input = input().split() + + # Replace %text% with user input + if '%first_name%' in self.text: + self.text = self.text.replace('%first_name%', self.first_name()) + if '%location%' in self.text: + self.text = self.text.replace('%location%', self.location()) + if '%whole_number%' in self.text: + self.text = self.text.replace('%whole_number%', self.whole_number()) + if '%plural_noun%' in self.text: + self.text = self.text.replace('%plural_noun%', self.plural_noun()) + + + def first_name(self): + #return input("A first name: ") + return self.input.pop() + + def location(self): + #return input("A location: ") + return self.input.pop() + + def whole_number(self): + #return input("A whole number: ") + return self.input.pop() + + def plural_noun(self): + #return input("A plural noun: ") + return self.input.pop() + +if __name__ == '__main__': + # Construct a mad lib + md = mad_lib('%first_name% went to %location% to buy %whole_number% different types of %plural_noun%') + + print(md.text) diff --git a/4/4.17/main.py b/4/4.17/main.py new file mode 100644 index 0000000..f5891a3 --- /dev/null +++ b/4/4.17/main.py @@ -0,0 +1,8 @@ +from mad_lib import mad_lib + +while True: + md = mad_lib('Eating %whole_number% %plural_noun% a day keeps the doctor away.') + if 'quit' in md.text: + break + else: + print(md.text) diff --git a/4/4.2/4.2.3/main.py b/4/4.2/4.2.3/main.py new file mode 100644 index 0000000..bfad071 --- /dev/null +++ b/4/4.2/4.2.3/main.py @@ -0,0 +1,5 @@ +user_num = int(input()) + +while user_num >= 1: + user_num = user_num / 2 # We operate on the value first, before printing it + print(user_num) diff --git a/4/4.3/4.3.3/main.py b/4/4.3/4.3.3/main.py new file mode 100644 index 0000000..a03e035 --- /dev/null +++ b/4/4.3/4.3.3/main.py @@ -0,0 +1,9 @@ +num_insects = int(input()) # Must be >= 1 + +result = [] + +while num_insects <= 100: + result.append(num_insects) + num_insects = num_insects * 2 + +print(*result, end = ' ') diff --git a/4/4.5/4.5.2/main.py b/4/4.5/4.5.2/main.py new file mode 100644 index 0000000..f0a8eef --- /dev/null +++ b/4/4.5/4.5.2/main.py @@ -0,0 +1,12 @@ +contact_emails = { + 'Sue Reyn' : 's.reyn@email.com', + 'Mike Filt': 'mike.filt@bmail.com', + 'Nate Arty': 'narty042@nmail.com' +} + +new_contact = input() +new_email = input() +contact_emails[new_contact] = new_email + +for contact in contact_emails: + print('{0} is {1}'.format(contact_emails.get(contact), contact)) diff --git a/4/4.8/4.8.1/main.py b/4/4.8/4.8.1/main.py new file mode 100644 index 0000000..c53c62a --- /dev/null +++ b/4/4.8/4.8.1/main.py @@ -0,0 +1,8 @@ +num_rows = int(input()) +num_cols = int(input()) + +for _i in range(num_rows): + print('*', end=' ') + for _i in range(num_cols - 1): + print('*', end=' ') + print() \ No newline at end of file diff --git a/4/4.8/4.8.2/main.py b/4/4.8/4.8.2/main.py new file mode 100644 index 0000000..4ea595c --- /dev/null +++ b/4/4.8/4.8.2/main.py @@ -0,0 +1,11 @@ +num_rows = int(input()) +num_cols = int(input()) + +# Note 1: You will need to declare more variables +# Note 2: Place end=' ' at the end of your print statement to separate seats by spaces + +for row_num in range(1, num_rows + 1): + for col_char in map(chr, range(ord('A'), ord('A') + num_cols)): + print('{0}{1}'.format(row_num, col_char), end=' ') + +print() \ No newline at end of file