In: Computer Science
In the code cell below, use two input() commands to collect two positive, non-zero integers from the user. These values represent the starting and ending values of a range (you may assume that the first value is always strictly less than the second value).
Next, use a loop to examine and count every integer in the range (including the starting and ending values) that contains at least one 7 among its digits. When your loop ends, print the total number of integers that contain at least one 7 and no other output.
For example, the input values 42 and 75 would produce the result 9 (within that range, we have the numbers 47, 57, 67, 70, 71, 72, 73, 74, and 75).
for example:
# Assume that my_number already has a value
number_string = str(my_number)
if 7 in number_string: # Add the rest of your code below...
Python code:
#accepting starting value
start=int(input())
#accepting ending value
end=int(input())
#setting count of numbers having 7 as 0
count=0
#looping each number in range
for my_number in range(start,end+1):
#converting that number to string
number_string=str(my_number)
#checking if 7 is in that string
if '7' in number_string:
#incrementing
count
count+=1
#printing count
print(count)
Screenshot:
Input and Output: