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
  • With using Python . Write a function that: 1. Takes two arguments and returns the product...

    With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle...

    In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle : - radius (input argument) - area (output argument, to be calculated) - circumference (output argument, to be calculated) All arguments are double type. If a radius is negative, the function returns false, otherwise it returns true. The function does only calculation, and does nothing else. Assume that all #include are already there                                     // Fill in your Function prototype bool circleAreaAndCircumference ( _______,...

  • IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer...

    IN PYTHON Write a function called printDigits() that requests the user to input a four-digit integer and prints the digits using math function, as shown below. You are not allowed to process the number as a string. You must process the number using standard arithmetic operators (+, *, /, %, etc.) >>> printDigits() Enter n: 1234 1 2 3 4 >>> printDigits() Enter n: 9876 9 8 7 6 >>>

  • PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

    PYTHON 4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function. 5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt"). 6. Ask the user for 5...

  • Task 5 Write a function called “earring_iter” that takes two integer arguments, size and count. This...

    Task 5 Write a function called “earring_iter” that takes two integer arguments, size and count. This function should use a (for or while) loop to draw a Hawaiian earring containingcount-manycircles,wherethefirstcircledrawnhassizesize,andeachsubsequent circle has size earring_ratio times the size of the previous circle. Here is a recursive specification for drawing a Hawaiian earring of a given size: • To draw a Hawaiian earring of a given size with zero hoops, do nothing. • To draw a Hawaiian earring of a given size...

  • Write a Python function binom_product that takes integer arguments a and b and positive integer argument...

    Write a Python function binom_product that takes integer arguments a and b and positive integer argument n and returns the product of the coefficients in the expansion of (ax + by)”. Example: Let a = 2, b = -1, and n = 3. Then (2x – y)3 = 8x3 – 12x²y + 6xy2 – 43 The product of the expansion coefficients is 8 x -12 x 6 x -1 = 576 Notes: There are two visible test cases and three...

  • Python 3: Write a function called every_other_character() that takes in a string and returns a new...

    Python 3: Write a function called every_other_character() that takes in a string and returns a new string with every other character removed. That is, the new string will include the first, third, fifth, etc. letters of the given string. Must use a while or for loop in the solution.

  • Python 3.0 Please Write a function that takes, as arguments, a binary string, a list of...

    Python 3.0 Please Write a function that takes, as arguments, a binary string, a list of characters and the corresponding Huffman code for those characters. It decodes the binary string using the Huffman code, and returns the resulting decoded string. Name this function decodeStringHuffman(binaryString, myCharacters, myCode). For example, >>>decodeStringHuffman("1001100010111010101010111", ["A", "B", "C"], ["1", "00", "01"]) should return the string 'ABAABCCAACCCCCAA'

  • Python 3: Write a function CharCount, to take a string S and a single character C,...

    Python 3: Write a function CharCount, to take a string S and a single character C, and returns the count of C (one letter) in the string S. If the letter of C is not found in S, the function returns -1. You must write your own function to do this and can not use any built-in counting functions. Use the function in main to get two inputs from the user, a sentence and a character, then show the count...

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