Python Forum
why it doesn`t stop at first double numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why it doesn`t stop at first double numbers
#1
     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%
Reply
#2
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.
Reply
#3
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
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  len() function, numbers doesn't work with Geany Editor Penguin827 3 2,989 May-08-2020, 04:08 AM
Last Post: buran
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,707 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020