a6q1 - else: return x ## Testing: ## uw_userid...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
## CS116 Assignment 6 Question 1 ## Ru Wang r46wang 20319247 ## uw_userid: string[nonempty] string[nonempty] string[nonempty] -> string[8 or less] ## This function consumes 3 nonempty strings and returns 1 string of a maximum length of 8. It contains the initial letters of the first and second string added upon the third string. ## Examples": ## uw_userid ("lori", "michelle", "case") => "lmcase" ## uw_userid ("John", "Paul", "Abbott") => "JPAbbott" ## uw_userid ("Bruce", "James", "Springsteen") => "BJSpring" def uw_userid(first, middle, last): x = first[0:1] + middle[0:1] + last if x>8: return x[0:8]
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else: return x ## Testing: ## uw_userid ("lori", "michelle", "case") => "lmcase" print "Test 1" expected = "lmcase" ans = uw_userid("lori", "michelle", "case") print ans==expected assert ans == expected ## uw_userid ("John", "Paul", "Abbott") => "JPAbbott" print "Test 2" expected = "JPAbbott" ans = uw_userid ("John", "Paul", "Abbott") print ans==expected assert ans == expected ## uw_userid ("Bruce", "James", "Springsteen") => "BJSpring" print "Test 3" expected = "BJSpring" ans = uw_userid ("Bruce", "James", "Springsteen") print ans==expected assert ans == expected...
View Full Document

Ask a homework question - tutors are online