## Practice Problems for Module 3

# Part 1 - Warm up questions

# Write a Python function switch_two that consumes 
# s (a string containing at least two characters) and 
# p1 and p2 (two integers between 0 and len(s)-1, with p1<p2) 
# and returns a new string like s, except with the characters 
# at positions p1 and p2 exchanged. 
# For example, switch_two("abcdef", 1,3) => "adcbef".

def switch_two(s,p1,p2):
    pass 


# Run the following code from Wing's definitions window. Ensure you
# understand why you see nothing in the interactions window. 

x = -4
s = "abc"
t = "abde"
smaller = min(s,t)
max(s,t)

# Uncomment and run the following code from Wing's definitions window. Ensure you
# understand what is printed in the interactions window. 

#print(x)
#print("Smaller of", s, "and", t, "is", smaller)
#print("Larger is", max(s,t))


# Write a Python function analyze_string that consumes a string s 
# and prints the following two lines to the screen:
#s
#contains C characters, P spaces, and ends with E
# where C is the length of s, 
# P is the number of spaces (' ') in s, and E is the last character in s.
# 
# For example, suppose analyze_string("To infinity and BEYOND!!!") was called, 
# the function prints
#To infinity and BEYOND!!!
#contains 25 characters, 3 spaces, and ends with !
# The function produces None.
#
# Note that no recursion is needed here - use string methods as needed.
# Be sure to complete the entire design recipe.

def analyze_string(s):
    pass


# Write a function check_bounds that consumes two integers (lower and upper, where lower <= upper),
# and asks the user to input an integer. If the inputted integer k satisfies
# lower <= k <= upper, the function returns True. Otherwise, the function returns False.
# You may assume that the user will input an integer.

def check_bounds(lower, upper):
    pass

# Write a Python function format_data that consumes
#   three different natural numbers (x,y,z), and prints
#   a message in the following form (over two lines): 
#The smallest value is MIN. The largest value is MAX.
#The middle value is MID.
#   where MIN is min(x,y,z), MAX is max(x,y,x), and MID is the other value.
#   The function returns None.
#
# Use format in your solution, and use only one print statement in your solution.

def format_data(x,y,z):
    pass

# Part 2 - Extra Practice

# Problem 1
## Write a function new_name that consumes two strings, one containing a 
## person's name current name, and the second containing the person's new 
## last name. The function returns the person's updated name 
## (which might be exactly the same). 
## For example, new_name("Abigail Melissa Smith", "Jones") => 
## "Abigail Melissa Jones", 
## new_name("Hao Chan", "Chan") => "Hao Chan", and
## new_name("Timothy Howe", "Howe-Williams") => "Timothy Howe-Williams"

# Problem 2
## Write a function create_email that consumes three strings:
## - first (for the first name)
## - last (for the last name)
## - domain, 
## and creates and returns an email address as follows:
## F.L@domain
## with the following restrictions:
## * the string F.L contains at most 10 characters (including the period)
## * the string F contains at most 8 characters from first
## * the string L contains at least 1 character from last
## * all characters are lower case
## * F, L contain no spaces or hyphens
##
## You may assume that first and last may contain spaces and hyphens. 
## You may assume that domain does not contain any spaces and hyphens.
##
## examples: 
## create_email('Jenn', 'Heil', "van2010.olym") => "jenn.heil@van2010.olym"
## create_email("Mike", "Robertson", "van2010.olym") 
##     => "mike.rober@van2010.olym"
## create_email("Alexandre", "Bilodeau", "van2010.olym") 
##     => "alexandr.b@van2010.olym"
## create_email("Mae Jo", "Ab-Ner", "MadeUp.com") 
##     => "maejo.abne@madeup.com"
##
## Hmmm - guess when this example problem was written!

# Problem 3
## A name is a string of the form
## Title First_Name Last_Name, where
## Title is "Mr.", "Mrs.", "Miss", "Dr.", "Sir", "Lady",
## and there is a single whitespace between each part of the name.
## For example, "Mr. Justin Case" or "Miss Alice Inwonderland".
##
## Write a function new_title which consumes a name
## and returns a new name, which is the same as the first, except
## that if the title was "Miss" or "Mrs.", the new name has
## the title "Ms.".
##

# Problem 4:
## Write a Python function check_password which consumes a string and a 
## natural number. The function then repeatedly asks the user to input their
## password, until it matches the consumed string or until the user has made
## N incorrect guesses, where N is the consumed number. The function prints
## Welcome
## if the password is guessed correctly and it returns True.
## If the password is not guessed correctly and the user runs out of guesses,
## then
## Access Denied
## is printed, and False returned.

# Problem 5
## Write a Python function draw_triangle that consumes a natural number, n, 
## and prints a triangle over n lines, as shown below. The function produces None.
##
## draw_triangle(3) prints
## X
## XX
## XXX
##
## draw_triangle(6) prints
## X
## XX
## XXX
## XXXX
## XXXXX
## XXXXXX