Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment will give you more experience on the use of loops In this project, we are going to compute the number of times a

This assignment will give you more experience on the use of loops In this project, we are going to compute the number of times a given digit D appears in a given number N. For example, the number of times 5 appears in 1550 is 2. The number of times 0 appears in 1550 is 1. The number of times 3 appears in 155 is 0. Etc.

image text in transcribedimage text in transcribed

ASSIGNMENT 1 50 points Overvicw This assignment will give you more experience on the use of loops In this project, we are going to compute the number of times a given digit D appears in a given number V. For example, the number of times 5 appears in 15500 is 2. The number of times 0 appears in 1550 is 1. The number of times 3 appears in 155 is 0. Ele. Task Your task is to implement the following the algorithm 1- initialize a counter to 0 2- decompose the number V into its corresponding digits by caleulating quotients and remainders of dividing it by 10 3- increment the counter each time the digit D appears Example: Given the number N- 1550 and the digit D 5 Calculated Digit Counter 0 2 2 l'roject Description / Specification 1. lPrompt the user for the given number and the given digit 2. The program should have error checking to make sure the user inputs are valid. For example, if a user gives non-integer inputs, notify the user that the inputs are incorrect and prompt again. 4. Decompose the number in a loop and increment the counter within the loop as described in the example above Helpful hint To check if a string consists of digits only, you can use the "isdigit" mcthod of the "str" type. Test out this method by assigning different string values to a variable, say "A, and then calling the "digits" method on this variable, as in "Aisdigit)". Type "help(str.isdigit)" to find more information. An example interaction and crror handling Enter a number ABCD Numher must be a positive integer! Try again Enter a number -3432432 Number must be a positive integer ! Try again Enter a number: 85454.32 Number must be a positive integer ! Try again Enter a number 56442 Enter a digil to be searched in number 15 Digit must be in the range 0...9 Enter a digit to be searched in number 4 Number of 4's in 56442 is 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions