print(line_size*c) # second print(c + ' '*(2+h) + '--' + (' '*(2*h + 2) + '--')*l + ':~' + c) # height lines for i in range(h): s1 = c+ ' '*(1 + h - i) + '/' s2 = (' '*(2 + 2*i) + '\\' + ' '*(2*(h - i)) + '/')*l s3 = ' '*(4+i) + c print(s1+s2+s3) # second last print(c + '--' + (' '*(2*h + 2) + '--')*l + ' '*(4+h)+c) # last line print(line_size*c) # Test check.set_print_exact('#########\n# --:~#\n# / #\n#-- #\n#########') check.expect('Q4T1',frame(1,0,'#'),None) def snake(): ''' Reads an input from the user with inputs for height(Int), length(Int) of the snake frame and the input of the framing character (Str). Effects: * reads input which is an integer for height or length * reads input which is a string for the framing character * prints to the screen snake(): None -> None requires:
return None elif n == 0 and secret != str_to_int: print(countdown.format(correct, incorrect)) print("Sequence of" + " " + str_space + " " + "not found. Game Over.") return None else: print(countdown.format(correct, incorrect)) return mastermind_helper(secret, turns - 1, n) ## Test check.set_input("1 2 3 4") check.set_print_exact( "There are 2 numbers in correct places and 0 numbers in incorrect places.", "Sequence of 1 6 1 4 not found. Game Over.") check.expect("Q4T11", mastermind_helper([1, 6, 1, 4], 1 - 1, 7), None) check.set_input("1 6 1 4") check.set_print_exact("Sequence found in 1 guesses.") check.expect("Q4T12", mastermind_helper([1, 6, 1, 4], 7 - 1, 7), 1) def mastermind(secret, turns): ''' Consumes a secret list of numbers (secret), the number of turns left (turns). Returns the number of guesses the guesser has left if there are still turns left or returns None when turns run out. And the following is printed: * prints the numbers in the correct and incorrect places
return mastermind_helper(secret, turns - 1, guess) def mastermind(secret, turns): '''Returns the number of guesses the guesser takes to determine the sequence. Given a list of integers secret of size at least 2 and the maximum number of turns the guesser has to determine secretIf secret is not guessed in turns guesses, the function returns None. The file prompts the user to input a sequence of number to find out the number of elements in two lists that are in the same place, and determining the number of elements in two lists that match but are in different locations. mastermind: (listof Int) Nat -> (Anyof None Nat) Requires: ''' return mastermind_helper(secret, turns, turns) #Example 1 check.set_input(' 1 2 3 4', ' 6 2 3 5', ' 1 1 6 4', '1 6 1 4') check.set_print_exact( 'There are 2 numbers in correct places and 0 numbers \ in incorrect places.', 'There are 0 numbers in correct places and 1 numbers \ in incorrect places.', 'There are 2 numbers in correct places and 2 numbers \ in incorrect places.', 'Sequence found in 4 guesses.') check.expect('Example1', mastermind([1, 6, 1, 4], 5), 4)
scrabble score("Hello!") -> 0 and prints "Invalid character!" scrabble score("") -> 0 and prints "Invalid character!" scrabble score("Hello") -> 8 ''' if not s.isalpha(): print("Invalid character!") return 0 s = s.upper() return word_score(s, 0) # Examples check.expect("Q1E1", scrabble_score("Hello"), 8) check.set_print_exact("Invalid character!") check.expect("Q1E2", scrabble_score("Hello!"), 0) check.expect("Q1E3", scrabble_score("zyZZyx"), 40) check.set_print_exact("Invalid character!") check.expect("Q1E4", scrabble_score("I like zyZZyx"), 0) # Test # all lower case letters check.expect("Q1T5", scrabble_score("helloworld"), 17) # empty string check.set_print_exact("Invalid character!") check.expect("Q1T6", scrabble_score(""), 0) # one space check.set_print_exact("Invalid character!") check.expect("Q1T7", scrabble_score(" "), 0) # all upper characters
"Enter password:"******"Enter password:"******"oodPass12!@@") check.set_print_exact("Good") check.expect("Test1", new_password(), None)
and prints "computers" ''' s = s.lower() if len(s) == 0: return "" elif not s[0].isalnum(): return "" + removal(s[1:]) elif s[0].isalpha(): return s[0] + removal(s[1:]) elif s[0].isdigit(): return "" + removal(s[1:]) else: return removal(s[1:]) ## Upper and Lower Char check.set_print_exact("mom") check.expect("Q2T1:", print(removal("moM")), None) ## Not palindrome check.set_print_exact("computers") check.expect("Q2T2:", print(removal("computers")), None) def reversal(s): ''' Consumes a string and returns the string in reverse reversal: Str -> Str Requires: * ignores non alphanumeric characters * reverses both numbers and alphabetic characters
def letter_update(secret, dashes, guess): if secret == "": return "" if secret[0] == dashes[0]: return secret[0] + letter_update(secret[1:], dashes[1:], guess) elif guess == secret[0]: return guess + letter_update(secret[1:], dashes[1:], guess) else: return "-" + letter_update(secret[1:], dashes[1:], guess) def update_dashes(secret, dashes, guess): print(letter_update(secret, dashes, guess)) ##Examples: check.set_print_exact("p-----") check.expect("Example 1:", update_dashes("python", "p-----", "x"), None) check.set_print_exact("b-bb-e") check.expect("Example 2:", update_dashes("bubble", "b-bb--", "e"), None) check.set_print_exact("b-bb--") check.expect("Example 3:", update_dashes("bubble", "------", "b"), None) ##Tests: check.set_print_exact("spring") check.expect("Q3T1", update_dashes("spring", "sprin-", "g"), None) check.set_print_exact("--ll---") check.expect("Q3T2", update_dashes("college", "--ll---", "l"), None) check.set_print_exact("---------") check.expect("Q3T3", update_dashes("firetruck", "---------", "w"), None)
else: return 0 def check_space(n): if n == "": return 0 if n != " ": return 1 else: return 0 + check_space(n[1:]) ##Examples: check.set_input("goodPlace12!@@") check.set_print_exact(" Good") check.expect("Example 1:", new_password(), None) check.set_input("fairPlace !!!") check.set_print_exact(" Fair") check.expect("Example 2:", new_password(), None) check.set_input("weak12") check.set_print_exact(" Weak") check.expect("Example 3:", new_password(), None) ##Tests: check.set_input("1234") check.set_print_exact(" Weak") check.expect("Q4T1", new_password(), None)