1. Write a program that asks a user to enter an integer and a number n between 0
ID: 3589485 • Letter: 1
Question
1. Write a program that asks a user to enter an integer and a number n between 0 and 9. The program should count the number of n’s in the integer. For example, if the user types in the integer 345924 and 4, your program will report that the number four appears two times. You can use the function len() to discover the number of digits of the number, if s = ’123456789’, len(s) = 9.
Example #1. 1 Enter a number 123456789 a Enter a digit between 0 and 9: 7 a The number 7 appears 1 time(s) Example #2 1 Enter a numer 77840123 2 Enter a digit between 0 and 9: 7 a The number 7 appears 2 time (s)Explanation / Answer
number = input("Enter a number : ")
digit = int(input("Enter a digit between 0 and 9 : "))
count = 0
for i in range(0, len(number)):
if(digit == int(number[i])):
count+=1
print("The number %s appears %s time(s)" %(digit, count))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.