Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop issues
#1
What am I doing wrong here? From what I can tell, my for loop (for x in s1) is not actually looping through the characters. But I don't know how to fix it.



# Type your code here
  
def find_mismatch(s1,s2):
    count = 0
    s1 = s1.lower()
    s2 = s2.lower()
    s1 = list(s1)
    s2 = list(s2)
    #print(s1, s2)
    
    if len(s1) != len(s2):
        return 2
    
    elif s1 == s2:
        return 0
    else:
        for x in s1:
            for y in s2:
                if y != x:
                    count += 1
            #return count
            
            if count < 2:
                return 1
            else:
                return 2
Output:
Your function return is NOT CORRECT. For example when your function is called as shown below: find_mismatch('Hello There', 'helloothere') Your function returns: 2 The correct return value is: 1
Reply


Messages In This Thread
For loop issues - by BigEasy - Feb-12-2018, 04:29 PM
RE: For loop issues - by nilamo - Feb-12-2018, 05:08 PM
RE: For loop issues - by BigEasy - Feb-12-2018, 05:52 PM
RE: For loop issues - by nilamo - Feb-12-2018, 06:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Having issues getting a loop to work PLESSE HELP ASAP manthus007 1 2,135 Aug-25-2018, 10:44 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020