Praštevila
Naloga
Uporabnik naj vpiše število. Program mora ugotoviti, ali je to praštevilo ali ne. (Praštevilo je tisto število, ki je deljivo s samim seboj in z 1 in nima drugih deliteljev)
Primer rešitve
import sys number = input("Vnesi stevilo" + "\n" + ">>>") number = int(number) prime = False #initiate boolean for true false, default false if number > 0: for x in range (2, number - 1): #this range excludes number and 1, both of which number is divisible by if number % x != 0: #If number isn't evenly divisible by x, start over with the next one continue elif number % x == 0: #If number is evenly divisible by x, it can't be prime print("To ni prastevilo") quit() print("To je prastevilo") #number wasn't evenly divisible by any x, so it's prime quit() elif number == 0: print("To ni prastevilo") #According to the Google, 0 is not prime quit() else:#if number is less than 0, the number is not prime (according to the Google). print("To ni prastevilo.") quit()
Poženi program
Počisti