【Python】基础练习题-1
#练习1:从键盘输入两个数,并比较其大小,直到输入e/E退出程序
while 1:
input_number=raw_inut("please input two numbers,enter "e" or "E" to exit:")
try:
if input_number.isdigit():
lst=[]
lst_new=lst.append(input_number)
if lst_new[0]>lst_new[1]:
print "%s大于%s",%(lst_new[0],lst_new[1])
elif st_new[0]<lst_new[1]:
print "%s小于%s",%(lst_new[0],lst_new[1])
else:
print "%s等于%s",%(lst_new[0],lst_new[1])
else:
raise TypeError
if input_number=="e" or input_number=="E":
break
except TypeError:
print "input is not a number,try again" #练习2:将列表元素交替地作为建和值来创建字典
lst=[1:"a",2:"b",3:"c"]
dicts={}
for i in range(0,len(lst),2):
dicts[lst[i]]=lst[i+1]
print dicts #练习3:分别输出字符串中奇数坐标和偶数坐标的字符
num=["a","b","c","d",1,2,3,4]
oddindex_number=[]
evenindex_number=[]
for i in range(0,len(str)):
if i%2!=0:
oddindex_number.append(num[i])
else:
evenindex_number.append(num[i])
print "奇数坐标的字符为:",oddindex_number
print "偶数坐标的字符为:",evenindex_number #练习4:将一个字典的 key和value 互换
dicts={1:4,2:5,3:6}
new_dicts={}
for k,v in dicts.items():
if isinstance(v,(str,float,tuple,int,complex)):
#print k,v
new_dicts[v]=k
else:
print u"value %s不可哈希" %v
print new_dicts #这是个递归的一个例子
def fib(num):
result=[0,1]
for i in range(num-2):
result.append(result[-2]+result[-1])
return result ptint fib(10)
【Python】基础练习题-1的更多相关文章
- python基础练习题1
深深感知python基础是有多么重要,Ljh说一定要多练题,so,我现在开始要每天打卡练习python.加油! 01:求‘1-100’的偶数和 #第一种解法: sum=0 num=0 while nu ...
- python基础练习题(九九乘法表)
又把python捡起来了,动手能力偏弱,决定每日一练,把基础打好! ------------------------------------------------------------------ ...
- python基础练习题
购物车程序 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/3/6 21:01 # @Author : hyang # @Si ...
- Python基础 练习题
DAY .1 1.使用while循环输出 1 2 3 4 5 6 8 9 10 n = 1 while n < 11: if n == 7: pass else: print(n) n ...
- Python基础练习题100例(Python 3.x)
1:题目:有四个数字:1.2.3.4,能组成多少个互不相同且无重复数字的三位数?各是多少? 程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成所有的排列后再去 掉不满足条件的排列. 程序源 ...
- python基础练习题30道
1.执行python脚本的两种方式 答:1>可以在python /home/xxxx.py 2>cd /home ./xxxx.py 因为py脚本里面指定了python解释器的位置 ...
- 08: python基础练习题
1.while循环实现输出2 - 3 + 4 - 5 + 6 ... + 100 的和 # 使用while循环实现输出2 - 3 + 4 - 5 + 6 ... + 100 的和 s = 0 i = ...
- 『Python基础练习题』day02
1.判断下列逻辑语句的True, False 1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2) ...
- Python学习【day03】- Python基础练习题(列表、元组、字典)
#!/usr/bin/env python # -*- coding:utf8 -*- # 1.有两个列表 # l1 = [11,22,33] # l2 = [22,33,44] # a.获取内容相同 ...
- Python学习【day02】- Python基础练习题
#!/usr/bin/env python # -*- coding:utf8 -*- # 执行Python 脚本的两种方式 # 答:①在windows的cmd窗口下 > D:/Python/p ...
随机推荐
- zend framwork项目基本操作
1.首先,我们做项目是采用db的方式来编写sql语句的. 2.查询: fetchOne() 查询一个字段,如果没有指定就只查询第一个字段,只能得到一个值. fetchRow() 查询一行数据 ...
- Git中ssh的使用
远程仓库前期工作(SSH HEY的使用) 1.1.注册GitHub账号 1.2.创建SSH Key 打开Git Bash后,输入ssh-keygen -t rsa -C "youremail ...
- MYSQL--三大范式
MYSQL--三大范式 范式简介: 设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称为不同的范式,各种范式呈递次规范,越高的范式数据库冗余越小.目前关系数据库有六 ...
- 在springboot中用redis实现消息队列
环境依赖 创建一个新的springboot工程,在其pom文件,加入spring-boot-starter-data-redis依赖: <dependency> <groupId&g ...
- Spring整合Hystrix
1.添加maven依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId> ...
- CentOS安装JDK-tar.gz文件
1.下载JDK,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. 测试 ...
- linux 安装Git详细过程
1.首先git --version 查看 Git https://mirrors.edge.kernel.org/pub/software/scm/git/ 2.下载 wget https://Gi ...
- 逆袭之旅DAY14.东软实训.Oracle.多表连接、分组函数、子查询
2018-07-10 08:29:55 思考应用场景 异常数据的测试 6.显示能挣得奖金的雇员的姓名.工资.奖金,并以工资和奖金降序排列.select ename,sal,commfrom empWH ...
- shell 通配符
Bash中的通配符 '?' 匹配一个任意字符 '*' 匹配0个或任意多个字符,也就是可以匹配任何内容 '[]' 匹配括号中任意一个字符.例如[abc]代表一定匹配一个字符,或者是a,或者是b,或者是c ...
- Python Django 之 直接执行自定义SQL语句(一)
一.执行自定义SQL方法 1.Executing custom SQL directly 直接执行自定义SQL,这种方式可以完全避免数据模型,而是直接执行原始的SQL语句. 2.Manage ...