S
S
Sergey Izovsky2021-09-13 15:58:08
Python
Sergey Izovsky, 2021-09-13 15:58:08

I can't solve the problem. Random multiples of 5?

Application certification CC-Python level 7. Problem №32 Random multiples 5. The
computer generates 300 random numbers in the range from 0 to 100 inclusive. Calculate the percentage of the resulting multiples of 7 numbers. In the first line, import the random library.

import random
c,  count = 0, 300
p = (c / count) * 100
for i in range(count):
    r = random.randint(0, 100)
    if (r % 7 == 0):
        c += 1
print(f"{p}%")


Displays an error help what's wrong in the application can not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2021-09-13
@Winsik

The error is most likely due to the fact that you are trying to compile in the second python, but it should be in the 3rd.
Well, the code itself with logical errors, first you need to do a loop, then only calculate the percentage, something like this:
https://www.online-python.com/mPtwa5nMHO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question