python练习1
2015-12-10 22:23
489 查看
1.输入三个变量,然后按小到大输出
x=int(input('输入x:'))
y=int(input('输入y:'))
z=int(input('输入z:'))
if x>y:
x,y=y,x
if x<z:
x,z=z,x
if y>z:
y,z=z,y
print x,y,z
2、输出100--200之间的素数
from math import sqrt
def isprime(n):
k=int(sqrt(n))
for i in range(2,k+1):
if n%i==0:
return 0
return 1
if __name__=='__main__':
for n in range(100,200):
if isprime(n)==1:
print (n)
x=int(input('输入x:'))
y=int(input('输入y:'))
z=int(input('输入z:'))
if x>y:
x,y=y,x
if x<z:
x,z=z,x
if y>z:
y,z=z,y
print x,y,z
2、输出100--200之间的素数
from math import sqrt
def isprime(n):
k=int(sqrt(n))
for i in range(2,k+1):
if n%i==0:
return 0
return 1
if __name__=='__main__':
for n in range(100,200):
if isprime(n)==1:
print (n)
相关文章推荐
- python 中__name__ = '__main__' 的作用
- python基础知识--字符串
- python中if __name__ == '__main__': 的解析
- python+Eclipse+pydev环境搭建
- python图像复制、显示、保存
- python 打开图像
- Python 字符串
- win7系统下配置openCV python环境附加 numpy +scipy安装
- Python中的字符串
- Python模块学习系列(3)----Scikit Learn(机器学习库)
- Python之open()函数详解
- python 中的counter类用法。重要
- python 中的counter类用法。重要
- Python Error: ImportError: cannot import name gof
- python语言特性及其数据类型
- python函数每日一讲 - compile()
- python字符串关键点总结
- python基础教程共60课-第30课字符串的索引和切片
- python基础教程共60课-第29课连接list
- python混合笔记(一)