Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers, randint
#3
(Nov-27-2023, 01:07 PM)deanhystad Wrote: It makes perfect sense to me hat or works. The and loops stops if either comparison is false. True and True == True, True and False == False, False and True == False, False and False == False. SO if a == 9 or if b == 20, the loop stops.

Or works because the only way for the loop to end is for both comparisons to be False: True or True == True, True or False == True, False or True == True, False or False == False. The only way for the loop to end with an or is for a != 9 to be False (a == 9) and b != 20 to be False (b == 20)

Maybe you'll like this better:
while not (a == 9 and b == 20):
What is the purpose of this code. It is really strange. Why not set a = 9 and b = 20 and c and d to random numbers?

There is no reason to initialize a, b, c and d to zero.

Why are you using tkinter? If you want a window to pop up and display the results, all you need is an input statement.
from random import randint

while True:
    a = randint(1,16)
    b = randint(13,29)
    c = randint(16,34)
    d = randint(22,40)
    if a == 9 and b == 20:
        break
print(a, b, c, d)
input()

Hello and thanks for reply.
The numbers given for a,b,c,d (i.e. 1-16) are mean numbers combined with standard deviations for each number, to define areas (swing) (i.e.: 1-16,13-29...)

Numbers i.e. 9,20 are part of lottery draw.
Reply


Messages In This Thread
random numbers, randint - by janeik - Nov-27-2023, 12:46 AM
RE: random numbers, randint - by deanhystad - Nov-27-2023, 01:07 PM
RE: random numbers, randint, SOLVED - by janeik - Nov-27-2023, 05:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output while using random.randint with def terickson2367 1 549 Oct-24-2023, 05:56 AM
Last Post: buran
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,324 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,793 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,582 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
Sad Iterate randint() multiple times when calling a function Jake123 2 2,109 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,344 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Help with a random.randint choice in Python booponion 5 2,850 Oct-23-2020, 05:13 PM
Last Post: deanhystad
  output a list of random numbers 'x' columns wide adityavpratap 4 3,066 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Can i prevent the random generator to generate already used numbers? MauserMan 3 2,935 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Inheriting, given number from randint is not working beLIEve 0 1,532 Oct-12-2019, 06:50 PM
Last Post: beLIEve

Forum Jump:

User Panel Messages

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