import random
tryes = 0
true = 0
allattempts = 0
attempts = 0
same = int(input("Количество чисел подряд ")) // number of numbers in a row required ex 2
mnum = int(input("Введите радиус ")) // radius (1-number) ex 2
repeats = int(input("Введите количество повторов (чем больше тем точнее) ")) // number of retries for better accuracy
number = random.randint(1, mnum)
while tryes < repeats :
copy = number
print(copy)
number = random.randint(1, mnum)
print(number)
attempts = attempts + 1
if number == copy :
true = true + 1
if copy != number :
true = 0
if true == same-1 :
attempts = attempts - (same - 1)
allattempts = allattempts + attempts
attempts = 0
tryes = tryes + 1
true = 0
print(str(tryes) + "/" + str(repeats))
-print(str(100/allattempts) + "%")
-input()
**Console log**
1
2
2
2
1/10
2
2
2/10
2
1
1
2
2
2
3/10
2
1
1
1
4/10
1
2
2
1
1
1
5/10
1
2
2
1
1
1
6/10
1
2
2
1
1
1
7/10
1
2
2
2
8/10
2
2
9/10
2
2
10/10
9.090909090909092%
Hello and welcome to the forums.
Please put your code in Python code tags. You can find
help here.
Also it would be helpful if you provide two sample inputs and outputs. One with actual result you get, and one with desired result.
i can`t more edit thread
desired result is
1
2
1
2
2
1/10
2
2
2/10
1
2
1
1
3/10
and ...
general is 2 same numbers in row
(Mar-23-2020, 09:55 PM)kris06383 Wrote: [ -> ]i can`t more edit thread
desired result is
1
2
1
2
2
1/10
2
2
2/10
1
2
1
1
3/10
and ...
general is 2 same numbers in row
I think I understand what you want your program to do. But I am not 100% sure.
Actually, I think your program may be working fine. What is confusing could be a lot of prints.
In each loop, there is:
print(copy) # previous number
number = random.randint(1, mnum)
print(number) # current number
So you need to check result in pairs, example:
Output:
(first iteration)
2
1
(second iteration)
1
2
(third iteration)
2
2
(two in a row).
Maybe try printing like this:
# ... code before
while tryes < repeats :
copy = number
print("previous number: ", copy)
number = random.randint(1, mnum)
print("current number: ", number)
print("-------")
# code after ...
Did this help? Please clarify more if I didn't answer your question.