Back to Course Lecture 1: Introduction and Strings 1 / 7
Tip: You can skip to a specific concept on this list
No concepts added for this class yet

Video Concepts in this class:

Count the Donuts ▼Hint ▲Hint

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.

    So donuts(5) returns 'Number of donuts: 5' and donuts(23) returns 'Number of donuts: many'.

Please to take this test and advance your course progress

Mix Up ▼Hint ▲Hint

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 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.

Please to take this test and advance your course progress

Both Ends ▼Hint ▲Hint

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 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.

Please to take this test and advance your course progress

Verbing ▼Hint ▲Hint

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 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.

Please to take this test and advance your course progress

Front Back ▼Hint ▲Hint

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.

  • 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

Please to take this test and advance your course progress

Not Bad ▼Hint ▲Hint

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 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!'.

Please to take this test and advance your course progress

Fix Start ▼Hint ▲Hint

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.


Please to take this test and advance your course progress

Google Python Class

Lecture 1's contents:

- Introduction to Python
- String type
- Some exercises

By Nick Parlante. Support materials and exercises: code.google.com

Interactive Shell