This code keep repeating the same sets of numbers that add up to a specific number. ex: 31+ 69 = 100. This will be repeated many times among other possibilities. What's the matter with my code ? enter image description here
Thanks. Here it is:
import random
target_number = int(input('Input a number and we will return a list of two numbers that equate to this number'))
r1 = range(1,target_number)
r2 = range(1,target_number)
while True:
for i in range(24):
num1 = random.choice(r1)
num2 = random.choice(r2)
if num1 + num2 == target_number:
print(f"solved: {num1}+{num2} = {target_number}")
for i in range(24)for? Do you want to print 24 pairs of numbers?while Trueloop has no way to exit. So it will run forever. What were you expecting to happen?num1to be random and just makenum2 = target - num1...