本帖最后由 wwwab 于 2023-1-14 16:00 编辑
我的码风是这个样子的:
[Python] 纯文本查看 复制代码 n=float(input("Please enter the number here:"))
m=int(n)
a=n.is_integer()
if m>=0 and a==True: #It means the number what the user entered is a nonnegative integer number, namely a natural number, and a necessary condition for a number to be a prime number is that the number to be a natural number.
if m<2:
print("False. The number you entered is:",str(m)," . Congratulations! It means it is not a prime number and it is a composite number.")
elif m==2:
print("True. The number you entered is:",str(m)," . Congratulations! It means it is a prime number.")
else:
for i in range(2, m):
if m%i==0:
print("False. The number you entered is:",str(m)," . Congratulations! It means it is not a prime number and it is a composite number.")
break
else:
print("True. The number you entered is:",str(m)," . Congratulations! It means it is a prime number.")
elif m<0:
print("False. Warning:The number you entered is:",str(m)," . What you entered is not an nonnegative number, it is a negative number, It does not belong to a natural number, nor can it belong to a prime number. Please try again!")
else:
print("False. Warning:The number you entered is:",str(m)," . What you entered is not an integer number, It does not belong to a natural number, nor can it belong to a prime number. Please try again!") #It means a==False
|