Checking if an integer contains a certain digit in a for loop [duplicate]

105
April 02, 2022, at 00:00 AM
This question already has answers here:
How to check if a specific digit is in an integer (5 answers)
Closed last month.

I am trying to solve this problem:

Write a code which computes the sum = 1/1 + ... 1/6 + 1/8 + ... +1/16 +... from 1 to 10000, skipping over the integers that contain the number 7.

Here is my code so far, I am stuck on trying to skip over the integers that contain the digit 7.

def int():
 sum=0
 for i in range(10000):
    if # integer contains digit==7:
        continue
    sum += 1/i
 return sum
Answer 1
def int():
    sum=0
    for i in range(1,10000): # make sure range is from 1 to whatever. Otherwise, you'll a ZeroDivisionError
        if '7' in str(i): #convert i to string
            continue
        sum += 1/i
    return sum
print(int())
Answer 2

if you want to check a digit in number use this

if "7" in str(i)
Rent Charter Buses Company
READ ALSO
Fast Python outer difference of list

Fast Python outer difference of list

I want to compute the difference between every element in a Python list of equally long lists and put it into a Numpy array

112
OpenCV VideoWriter Error "dimensions too large for MPEG-4"

OpenCV VideoWriter Error "dimensions too large for MPEG-4"

I have some frames (dimensions: 8192x2160) that are generated from concatenating two 4096x2160 frames side by sideWhen writing these frames to a video file using OpenCV VideoWriter, I get this error: dimensions too large for MPEG-4

167
What happens to selenium code simulating browser actiions when run in non GUI unix box? Will chrome windows open?

What happens to selenium code simulating browser actiions when run in non GUI unix box? Will chrome windows open?

I built my first selenium on a mac machine, so with help of chromedriver, I see a new tab opened by my script

131
Echarts line chart symbol formatter

Echarts line chart symbol formatter

above code print like this: https://istack

117