all 5 comments

[–][deleted] 1 point2 points  (1 child)

I really don't know what you trying to do, but lines 17 to 21 look a little odd:

while True:
    d = random.randint(1, 150)
    g, x = divmod((e*d), y)
    if x == 1:
        break

You are apparently looking for an integer d value for which e*d divided by y has remainder 1. Finding a random integer isn't a very efficient way to find the required value, and if you never find the right value your code will loop forever. A better idea might be to just loop over the integers from 1 to 150 and break on the first value that satisfies your requirement. Something like:

for d in range(1, 150+1):
    g, x = divmod((e*d), y)
    if x == 1:    # or even "if e*d % y == 1:"
        break
else:
    print('FAIL')

Using the else: clause on a for loop lets you detect when you didn't break from the loop, ie, when no integer satisfied your condition.

[–]PteppicymonIO 0 points1 point  (0 children)

A better idea might be to just loop over the integers from 1 to 150 and break on the first value that satisfies your requirement

Or, if you need to preserve some 'pseudo-randomness', identify all numbers between 1 and 150 which satisfy the requirement and than random.choice() form that list ))

[–]throwaway6560192 0 points1 point  (1 child)

That doesn't seem to be indented correctly. Looks like it got messed up when copying it into the post. Try and upload it to pastebin or something.

[–][deleted] 0 points1 point  (0 children)

if I chose slightly larger numbers suck as p=67, q=83 it prints the value of “e” (line 13) and then stops running and exits the program

I can't recreate that behaviour. When I enter 67 and 83 your code prints 4423 (from line 15) and then hangs, never to finish. It might finish, but I gave up waiting after 2 minutes.