id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

david.white@denison.edu cs112fall2015 > difference
prev  |  next  |  chance

Write a function difference(word1, word2) that returns the first index at which the strings word1 and word2 differ. If the words have different lengths, and the shorter word is a pre fix of the longer word, the function should return the length of the shorter word. If the two words are the same, the function should return −1. Do this without directly testing whether word1 and word2 are equal.


difference('words', 'wordiness') → 4
difference('notice: capiTalization matters', 'notice: capital') → 12
difference('c0c0nuts7', 'cOcOnuts8') → 1

...Save, Compile, Run (ctrl-enter)

def difference(word1, word2):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Copyright Nick Parlante 2017 - privacy