result_str = "Thyry wyry a lot of yseopyoplys in thy ylyvator on Tuysdae." print "Reversing: {}".format(test_str) print "Result: {}".format(swapchars(test_str)) print "Should be: {}".format(result_str) print "" print "Reversing: HeLlO" print "Result: {}".format(swapchars("HeLlO")) print "Should be: {}".format("HeOoL") print "" print "--- Question 3 ---" print "sortcat(1, 'abc', 'bc')" print "Gives: {}".format(sortcat(1, 'abc', 'bc')) print "Should be: {}".format('abc') print "" print "sortcat(2, 'bc', 'c', 'abc')" print "Gives: {}".format(sortcat(2, 'bc', 'c', 'abc')) print "Should be: {}".format('abcbc') print "" print "sortcat(-1, 'abc', 2)" print "Gives: {}".format(sortcat(-1, 'abc', 2)) print "Should be: {}".format("abc2") print "" print "--- Question 4 ---" print "Testing for 2000 trials..." trials = 2000 win_frac = look_away(trials) # Compute win loss counts based on fraction returned win = int(round(trials * win_frac)) loss = trials - win print "Luigi win/loss: {}/{} ({:.2f}%)".format(win, loss, win_frac*100.0)
# Expected output: 'what???2345' pprint(concat(-1, "what", "???", 5, 234)) # Expected output: '' pprint(concat(0, "kyle", "kyle", "kyle")) # Expected output: 'abcbcc' pprint(concat(3, 'bc', 'c', 'abc')) print print # Testing question 4a print "==testing question 4a==" #Expected output: Should be close to 0.6547, as calculated in question 4b pprint(look_away(10000)) pprint(look_away(10000)) pprint(look_away(10000)) pprint(look_away(10000)) pprint(look_away(10000)) print print print "==testing question 5a==" # Expected output: Varies depending on time used shuttles() print