码迷,mamicode.com
首页 > 编程语言 > 详细

python 判断质数还是合数

时间:2016-06-28 20:18:47      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

while 1:
   
   s = input(请输入一个数:)
   s = int(s)
   if s == 2:
      print(质数)
   else:
      if s == 0 or s == 1:
         print(都不是)
      else:    
         u = s - 2
         h = 1
         p = 1
         while u:
            h = h + 1
            if s % h == 0:
               p = 1
               break
            else:
               p = 0
            u = u - 1
         if p:
            print(合数)
         else:
            print(质数)
               
            

 

python 判断质数还是合数

标签:

原文地址:http://www.cnblogs.com/wumac/p/5624832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!