Question

w0='code' w1='door' mismatches=0 for letter in w0: if w0.count(letter)!= w1.count(letter): mismatches += w1.count(letter) print(mismatches) Answer is...

w0='code'
w1='door'
mismatches=0

for letter in w0:
if w0.count(letter)!= w1.count(letter):
mismatches += w1.count(letter)
print(mismatches)

Answer is 2 but how do we find this answer by Python code

0 0
Add a comment Improve this question Transcribed image text
Answer #1
w0 = 'code'
w1 = 'door'

go through each letter in w0
letter 'c'
    count of 'c' in w0 is 1, count of 'c' in w1 is 0
    counts are not equal. so, add count of 'c' in w1 to mismatch
    mismatch += 0
    so, mismatch is 0
letter 'o'
    count of 'o' in w0 is 1, count of 'o' in w1 is 2
    counts are not equal. so, add count of 'c' in w1 to mismatch
    mismatch += 2
    so, mismatch is 2
letter 'd'
    count of 'd' in w0 is 1, count of 'd' in w1 is 1
    counts are equal. so, we don't need to add anything to mismatch
letter 'e'
    count of 'e' in w0 is 1, count of 'e' in w1 is 0
    counts are not equal. so, add count of 'e' in w1 to mismatch
    mismatch += 0
    so, mismatch is 2

so, final value of mismatch is 2.
Answer: 2

Python code:
-------------
w0 = 'code'
w1 = 'door'
mismatches = 0

for letter in w0:
    if w0.count(letter) != w1.count(letter):
        mismatches += w1.count(letter)
print(mismatches)


Add a comment
Know the answer?
Add Answer to:
w0='code' w1='door' mismatches=0 for letter in w0: if w0.count(letter)!= w1.count(letter): mismatches += w1.count(letter) print(mismatches) Answer is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • # 3. PUT IN PYTHON CODE # Write a program that prints a count of how...

    # 3. PUT IN PYTHON CODE # Write a program that prints a count of how many occurrences of the letter "a" # there are in q. Do to this you will have to use a loop within a loop. q = ["apple", "beans", "orange", "tangerine", "butter", "watermelon", "vinegar"] # Type your answer here:

  • Paste this code into a new file and find the errors.  The most frequent letter in the...

    Paste this code into a new file and find the errors.  The most frequent letter in the user_string is H. # Function displays the character that appears most frequently # in the string. If several characters have the same highest # frequency, displays the first character with that frequency. def main():     # Set up local variables     count = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]     letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'     index = 0     frequent = 0     # Receive user input.     user_string = 'Who where what why how'     for ch...

  • Letter Count : Write a Python script that reads a file and outputs the number of...

    Letter Count : Write a Python script that reads a file and outputs the number of words that start with each letter. This means that for every letter we want to count the total number of (nonunique) words that begin with that letter. In your implementation you should ignore the letter case, i.e., consider all words as lower case. Output the results in the following format (below values are hypothetical): a or A: 120 b or B: 460 c or...

  • What is the output of the following Python code if the user enters 4? count =...

    What is the output of the following Python code if the user enters 4? count = int(input()) the_sum = 0 for i in range (1, count):     the_sum = the_sum + i print("Sum is", the_sum)

  • python Question#2: Write a NumPy program to count the number of days of a given month...

    python Question#2: Write a NumPy program to count the number of days of a given month for the given years. In [0]: import numpy as np print("Number of days, February, 2020: ") print() #TO DO -- Complete the Code print("Number of days, February, 2021: ") print() #TO DO -- Complete the Code print("Number of days, February, 2022: ") print() #TO DO -- Complete the Code Number of days, February, 2020: 29 days Number of days, February, 2021: 28 days Number...

  • Only do Q2 please!!! please Type the code in python!!!thanks Only do Q2 please!!! please Type...

    Only do Q2 please!!! please Type the code in python!!!thanks Only do Q2 please!!! please Type the code in python!!!thanks 1. (10 points) (Without Python) Unfortunately, Eddard is lost in the dark dungeon of the Red Keep. He knows there are three doors, and one of the doors will lead him to freedom. If Eddard takes Door A, he will wander around the dungeon for 3 days and return to where he started If he takes Door B, he will...

  • Python What do the following loops print? Work out the answer by tracing the code, not...

    Python What do the following loops print? Work out the answer by tracing the code, not by using the computer. a. s = 2 for n in range (1, 6): s = s + n print(s) b. s = 1 for n in range (1, 11): n = n + 2 s = s + n print(s) c. S = 1 for in range (1, 6) s = s + n n = n + 1 print(s, n) Rewrite the...

  • Part 1: Python code; rewrite this code in C#, run the program and submit - include...

    Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...

  • def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.")...

    def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.") print("Up to the number of times you chose, we will randomly choose 0 or 1.") print("If a 1 is chosen before the last drawing, then you lose.") print("If a 1 does not appear at all, then you lose.") print("You win if 1 is chosen for the first time exactly on the last drawing.") print() def first_to_a_word(): print("###### First to a Word ######") print("Instructions:") print("You...

  • Without using lambda in PYTHON How can I find the word "Code" and "code" on a website and print how many times they appear?

    Without using lambda in PYTHON How can I find the word "Code" and "code" on a website and print how many times they appear?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT