Remember that you can search in the assets/googleu folder, using Classroom.tv's python console, for text files with which you can practice and build up your answers before submitting.
Given an int count of a number of donuts, return a string of the form 'Number of donuts: <count>', where <count> is the number passed in. However, if the count is 10 or more, then use the word 'many' instead of the actual count.
'Number of donuts: <count>'
So donuts(5) returns 'Number of donuts: 5' and donuts(23) returns 'Number of donuts: many'.
'Number of donuts: 5'
'Number of donuts: many'
Please Login to take this test and advance your course progress
Given strings a and b, return a single string with a and b separated by a space '<a> <b>', except swap the first 2 chars of each string (e.g. 'mix','pod' gives 'pox mid' ; 'dog','dinner' gives 'dig donner').
Assume a and b are length 2 or more.
Given a string s, return a string made of the first 2 and the last 2 chars of the original string, so 'spring' yields 'spng'. However, if the string length is less than 2, return instead the empty string.
Given a string, if its length is at least 3, add 'ing' to its end. Unless it already ends in 'ing', in which case add 'ly' instead. If the string length is less than 3, leave it unchanged.
Return the resulting string.
Consider dividing a string into two halves. If the length is even, the front and back halves are the same length. If the length is odd, we'll say that the extra char goes in the front half (e.g. 'abcde', the front half is 'abc', the back half 'de').
Given 2 strings, a and b, return a string of the form
a_front + b_front + a_back + b_back
Given a string, find the first appearance of the substring 'not' and 'bad'. If the 'bad' follows the 'not', replace the whole 'not'...'bad' substring with 'good'. Return the resulting string.
So 'This dinner is not that bad!' yields: 'This dinner is good!'.
'This dinner is not that bad!'
'This dinner is good!'
s.replace(stra, strb) returns a version of string s where all instances of stra have been replaced by strb.
Given a string s, return a string where all occurences of its first char have been changed to '*', except do not change the first char itself (e.g. 'babble' yields 'ba**le').
Assume that the string is length 1 or more.
Google Python Class
Lecture 1's contents:
- Introduction to Python
- String type
- Some exercises
By Nick Parlante. Support materials and exercises: code.google.com
Please Login to post a question