Aug-08-2023, 07:04 PM
(This post was last modified: Aug-08-2023, 07:04 PM by FirstBornAlbratross.
Edit Reason: Added code tags
)
Hi all,
My exercise for today (not for school) is for the user to enter a number and then I have to find the next prime number and print it.
This is what I've got so far (it doesn't work):
Thanks.
Edit: I don't know how to make my code more readable on this site. Does anyone know?
My exercise for today (not for school) is for the user to enter a number and then I have to find the next prime number and print it.
This is what I've got so far (it doesn't work):
def nextPrime(): num = int(input("Enter a number: ")) next_num = num + 1 while True: for i in range(2, next_num): if (next_num % i) == 0: next_num += 1 else: break print(f"The next prime number is {next_num}.") nextPrime()I thought my logic was good, but apparently not. Any ideas?
Thanks.
Edit: I don't know how to make my code more readable on this site. Does anyone know?