python 02
程序员文章站
2022-04-28 13:31:32
...
1.判断用户输入的变量名是否合法:
#!/usr/bin/env python
import string
name = raw_input("name:")
if name[0] in string.letters+"_":
for i in name[1:]:
if i not in string.letters + "_" + string.digits:
print "name is wrong!!!"
exit(0)
print "name is right"
else:
print "name is wrong,please input right name!!!"
2.用户输入一个数字,判断是否为质数
#!/usr/bin/env python
num = input("num:")
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print (num,"is not zhishu")
break
else:
print (num,"is zhishu")
else:
print (num,"is not zhishu")
思维脑图链接:
这里写链接内容
下一篇: python 02