Question

Write a Python function, called counting, that takes two arguments (a string and an integer), and...

Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling.

You are not permitted to use the Python string methods (such as count(), etc.).

Sample input/output:

Please enter a string of digits: 34598205
Please enter a 1-digit value: 5
The number of digits that are not 5 is 6
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def counting(string, num):
    answer = 0
    for i in string:
        if int(i)!=num:
            answer += 1
    return answer

def main():
    s = input("Please enter a string of digits: ")
    i = int(input("Please enter a 1-digit value: "))
    print("The number of digits that are not",i,"is",counting(s,i))

main()

Output:

Please enter a string of digits: 34598205 Please enter a 1-digit value: 5 The number of digits that are not 5 is 6 Process fi

Add a comment
Know the answer?
Add Answer to:
Write a Python function, called counting, that takes two arguments (a string and an integer), and...
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
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