Home > Net >  prime number machine and if not working tkinter
prime number machine and if not working tkinter

Time:11-23

I am building a machine that can recognize prime numbers individually and show the result to the user,But there is a problem that I showed in the text below

>>12
>>12,is a not prime number
>>7
>>7,is a not prime number

Which prime number and which composite number can be converted into composite numbers my codes:

from tkinter import * 
def rso():
    a = int(text.get())
    for i in range(a   1):
        pass
    if a % i == 1:
        Label(app,text=(a,"is a  prime number"),font=20).pack()
    else:
        Label(app,text=(a,"is a NOT prime number"),font=20).pack()
app = Tk()
text = Entry(app,font=20)
text.pack()
Button(app,text="sumbit",font=20,command=rso).pack()
app.mainloop()

CodePudding user response:

Try this:

num = 3
flag = False

if num > 1:
    # check for factors
    for i in range(2, num):
        if (num % i) == 0:
            flag = True
            break

if flag:
    print(f"{num} is not a prime number")
else:
    print(f"{num} is a prime number")
  • Related