1.输入1-127的ascii码并输出对应字符

#-*-coding:UTF-8-*-

for i in range(0,128):

print chr(i)

2.输入a,b,c,d4个整数,计算a+b-c*d的结果

#-*-coding:UTF-8-*-

a=int(raw_input ("please input number a: "))

b=int(raw_input ("please input number b: "))

c=int(raw_input ("please input number c: "))

d=int(raw_input ("please input number d: "))

result=a+b-c*d

print result

3.计算一周有多少分钟、多少秒钟

#-*-coding:UTF-8-*-

minutes=7*60*24

print("There are %d minutes in one week" % (minutes))

senconds=7*24*60*60

print("There are %d senconds in one week" % (senconds))

4.3个人在餐厅吃饭,想分摊饭费。总共花费35.27美元,他们还想给15%的小费。每个人该怎么付钱,编程实现

#-*-coding:UTF-8-*-

money=35.27*1.15

everone=money/3

print ("everyone should give %f money" % (everone))

5.计算一个12.5m X 16.7m的矩形房间的面积和周长

#-*-coding:UTF-8-*-

length=12.5

width=16.7

area=length*width

print ("the area is %f" % (area))

perimeter=2*length+2*width

print ("the perimeter is %f" % (perimeter))

6.怎么得到9 / 2的小数结果

#-*-coding:UTF-8-*-

a=9.00

b=2.00

result=a/b

print ("the result is %f" % (result))

7.python计算中7 * 7 *7 * 7,可以有多少种写法

#-*-coding:UTF-8-*-

result1=7*7*7*7

print result1

import math

result2=math.pow(7,4)

print result2

result3=1

for i in range(1,5):

result3=result3*7

print result3

8.写程序将温度从华氏温度转换为摄氏温度。转换公式为C = 5 / 9*(F - 32)

#-*-coding:UTF-8-*-

fahrenheit=int(raw_input("please input the Fahrenheit: "))

celsius=(fahrenheit-32)*5/9

print ("it is %f celsius" %(celsius))

9.一家商场在降价促销。如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣,如果购买金额大于100元会给20%折扣。编写一程序,询问购买价格,再显示出折扣(10%或20%)和最终价格。

#一家商场在降价促销。如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣,如果购买金额大于100元会给20%折扣。编写一程序,询问购买价格,再显示出折扣(10%或20%)和最终价格

#-*-coding:UTF-8-*-

price=int(raw_input("please input the price: "))

after_price=0

if price>=50 and price<=100:

after_price=price*(1-0.1)

elif price>100:

after_price=price*(1-0.2)

else:

after_price=price

print ("the price is %f." %(after_price))

10.判断一个数n能否同时被3和5整除

#-*-coding:UTF-8-*-

number=int(raw_input("please input a number: "))

if number%3==0 and number%5==0:

print ("this number %d can be divisible by 3 and 5." %(number))

else:

print ("this number %d can't be divisible by 3 and 5." %(number))

11.求1 + 2 + 3 +….+100

#-*-coding:UTF-8-*-

result=0

for i in range (1,101):

result=result+i;

i=i+1;

print result

12交换两个变量的值

#-*-coding:UTF-8-*-

x=int(raw_input("please input the number x:"))

y=int(raw_input("please input the number y:"))

tmp=x

x=y

y=tmp

print x,y

a=int(raw_input("please input the number a:"))

b=int(raw_input("please input the number b:"))

a,b = b,a

print a,b

13一个足球队在寻找年龄在10到12岁的小女孩(包括10岁和12岁)加入。编写一个程序,询问用户的性别(m表示男性,f表示女性)和年龄,然后显示一条消息指出这个人是否可以加入球队,询问10次后,输出满足条件的总人数。

#-*-coding:UTF-8-*-

result=0

for i in range(1,11):

sex = raw_input("please input your gender:input f for girl,input m for boy: ")

age = int(raw_input("please input your age: "))

if sex == "f" and 10<=age<=12:

print "welcome!you can join the team."

result+=1

else:

print "sorry you can't join the team"

print ("it is %d can join the team" %(result))

14 长途旅行中,刚到一个加油站,距下一个加油站还有200km,而且以后每个加油站之间距离都是200km。编写一个程序确定是不是需要在这里加油,还是可以等到接下来的第几个加油站再加油。 程序询问以下几个问题: 1)你车的油箱多大,单位升 2)目前油箱还剩多少油,按百分比算,比如一半就是0.5 3)你车每升油可以走多远(km) 提示: 油箱中包含5升的缓冲油,以防油表不准。

#-*-coding:UTF-8-*-

capacity=int(raw_input("please input your car's capacity: "))

percentage=float(raw_input("please input your gas liter remaining percentage now: "))

speed=int(raw_input("please input 1 L gas can run how many km: "))

n=int((capacity*percentage*speed-5)/200)

if capacity*percentage<5:

print "you need add gas here"

elif n==0:

print "you need add gas here"

else:

print ("you need add gas in %d gas station." %(n))

15 现有面包、热狗、番茄酱、芥末酱以及洋葱,数字显示有多少种订购组合,其中面包必订,0不订,1订,比如10000,表示只订购面包

#-*-coding:UTF-8-*-

num = 0

bread=1

if bool(bread):

for hotdog in range(0,2):

for ketchup in range(0,2):

for mustard in range(0,2):

for onion in range(0,2):

num = num + 1

print bread,hotdog,ketchup,mustard,onion

print num

16 基于上题:给出每种食物的卡路里(自定义),再计算出每种组合总共的卡路里

#15 现有面包、热狗、番茄酱、芥末酱以及洋葱,数字显示有多少种订购组合,其中面包必订,0不订,1订,比如10000, 表示只订购面包

#16 基于上题:给出每种食物的卡路里(自定义),再计算出每种组合总共的卡路里

#-*-coding:UTF-8-*-

total_calories = 0

bread_calories=int(raw_input("please input the bread calories: "))

hotdog_calories=int(raw_input("please input the hotdog calories: "))

ketchup_calories=int(raw_input("please input the ketchup calories: "))

mustard_calories=int(raw_input("please input the mustard calories: "))

onion_calories=int(raw_input("please input the onion calories: "))

cal1=0

cal2=0

cal3=0

cal4=0

cal5=0

bread=1

totalcalorie=0

if bool(bread):

cal1=bread_calories

for hotdog in range(0,2):

if hotdog==1:

cal2=hotdog_calories

else:

cal2=0

for ketchup in range(0,2):

if ketchup==1:

cal3=ketchup_calories

else:

cal3=0

for mustard in range(0,2):

if ketchup==1:

cal4=mustard_calories

else:

cal4=0

for onion in range(0,2):

if onion==1:

cal5=onion_calories

else:

cal5=0

totalcalorie=cal1+cal2+cal3+cal4+cal5

print bread,hotdog,ketchup,mustard,onion,totalcalorie

17输入5个名字,排序后输出

#-*-coding:UTF-8-*-

name_1 = raw_input("please input name_1:")

name_2 = raw_input("please input name_2:")

name_3 = raw_input("please input name_3:")

name_4 = raw_input("please input name_4:")

name_5 = raw_input("please input name_5:")

a = [name_1,name_2,name_3,name_4,name_5]

b = sorted(a)

print b

19输入一个正整数,输出其阶乘结果

#-*-coding:UTF-8-*-

n=int(raw_input("please input a number: "))

result=1

for n in range (1,n+1):

result=result*n

print result

20 计算存款利息 4种方法可选: 活期,年利率为r1; 一年期定息,年利率为r2; 存两次半年期定期,年利率为r3 两年期定息,年利率为r4 现有本金1000元,请分别计算出一年后按4种方法所得到的本息和。 提示:本息= 本金+ 本金* 年利率* 存款期

#-*-coding:UTF-8-*-

money=1000

r1=0.02

money1=1000*(1+r1)

r2=0.03

money2=1000*(1+r2)

r3=0.04

money3=1000*(1+r3)

r4=0.06

money4=1000*(1+r4)

print money1,money2,money3,money4

21输入3个数字,以逗号隔开,输出其中最大的数

num=raw_input ("please input three number split by , :")

num2=num.split(',')

print num2

max_number=max(num2)

print max_number

22输入一个年份,输出是否为闰年 是闰年的条件: 能被4整数但不能被100整除,或者能被400整除的年份都是闰年。

#-*-coding:UTF-8-*-

year=int(raw_input("please input a year: "))

if year%4==0 and year%100!=0 or year%400==0:

print "this is leap year!"

else:

print "this is not leap year!"

23求两个正整数m和n的最大公约数

#-*-coding:UTF-8-*-

m=int(raw_input("please input number m: "))

n=int(raw_input("please input number n: "))

result=[]

x=0

if m>n:

x=n

else:

x=m

for i in range (1,x):

if m%i==0 and n%i==0:

result.append(i)

print result

b=sorted(result)

print b[-1]

python第一章测试题_python 第一章 初探Python课后练习题相关推荐

  1. python语言的语法_Python第一章基本语言语法

    第一章:基本语法 1.1.1基本的输入输出函数 Print ( ) 作用:输出字符串 用法1: print('代输出字符串') 用法2:用于输出一个或多个变量 print(变量1,变量2,-) 用法3 ...

  2. python第一周心得_python第一周心得-Go语言中文社区

    Python 简介 Python 作为一个近年备受好评的语言,它的一些优点让人无法忽视.Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言.它的设计具有很强的可读性,相比其他 ...

  3. python基础知识测试题_Python中的单元测试—基础知识

    python基础知识测试题 Unit testing is the number one skill which separates people who just finished their de ...

  4. python提取数据段_python提取数据段 python数据分析

    如何在python中用slice分段取数据? 执行以下操作:&gt&gt a=range(6)&gt&gt a[0, 1, 2, 3, 4,5]&gt& ...

  5. python 去掉双引号_python知识学习,python标识符和关键字

    python标识符和关键字 标识符和关键字都是之中具有某种意义的标记和称谓,就像人的外号一样.所谓的标识符就是代码的分号.单引号.双引号等等就是标识符,而代码中的if.for等等就是关键字. pyth ...

  6. [转载] python截取指定字符串_python字符串截取,python字符串切片的方法详解

    参考链接: Python字符串| min 字符串本质上就是由多个字符组成的,Python 允许通过索引来操作字符,比如获取指定索引处的字符,获取指定字符在字符串中的位置等. Python 字符串直接在 ...

  7. python自动化办公设置_python自动化办公之 python操作Excel

    今天就为大家介绍一下,使用 Python 如何操作 Excel . 常用工具 数据处理是 Python 的一大应用场景,而 Excel 又是当前最流行的数据处理软件.因此用 Python 进行数据处理 ...

  8. python idle有哪些_Python IDLE入门简介 Python IDLE与python有什么区别

    大神可以给小编介绍一下Python IDLE怎么用吗?真正长得漂亮的人很少发自拍,真正有钱的人基本不怎么炫富,真正恩爱的情侣用不着怎样秀恩爱发截图,真正玩的愉快的时候是没有多少时间传照片的,真正过得精 ...

  9. python高手之路_python高手之路python处理ex

    用python来自动生成excel数据文件.python处理excel文件主要是第三方模块库xlrd.xlwt.xluntils和pyExcelerator,除此之外,python处理excel还可以 ...

  10. python web开发入门_python大佬整理的python web开发从入门到精通学习笔记

    原标题:python大佬整理的python web开发从入门到精通学习笔记 Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象.直译式电脑编程语言,也是一种功能强大的通 ...

最新文章

  1. 求教大牛!关于后缀树
  2. Arduino IDE增加ATmega32开发选项遇到的问题
  3. requestAnimationFram
  4. 前端学习(2125):watch实现
  5. 张开双臂迎接“云时代“的到来
  6. 精雕道路怎么遍弧形_有网友私信我问郑州融信奥体世纪这个楼盘怎么样他今天来...
  7. 京东方计划为苹果iPhone 13供应6.06英寸OLED面板
  8. 列名 userid 不明确。 表结构_SQL-Server(三)表的创建和操作
  9. substring substr slice 区别
  10. 剖析 |数据现代化-富国银行的数据转型之路
  11. P1160 队列安排 (模拟链表)
  12. python爬虫淘宝评论图片_Python爬虫实战四之抓取淘宝MM照片
  13. 多旅行商问题(Multiple Traveling Salesman Problem, MTSP):单仓库多旅行商问题及多仓库多旅行商问题(含动态视频)
  14. 等等!python和鸭子是什么关系?
  15. WIN7下安装WIN2003系统
  16. Android学习|动画——逐帧、补间、属性动画
  17. 计算机组成原理之指令微操作(简化总结)
  18. redis主从配置及主从切换
  19. 【东哥视觉】做人做事禁忌
  20. B站500万粉up主党妹被黑客勒索:交钱赎“人”!顶级安全专家:无解

热门文章

  1. # Logistic regression中的threshold
  2. 安装liunx出现Entering emergency mode
  3. 磁盘清理软件:BlueHarvest for Mac
  4. List 接口和常用方法
  5. html中如何写平方根等,开方符号 数学符号平方根号等怎么输入
  6. vue接入DataV
  7. 创新、协调、绿色、开放、共享”五大发展理念整体上是一个彼此之间有联系、成结构的体系,是统一的,而从个体上来说,他们之间是相互促进、相互依赖、相互作用、相互对立的,这恰恰体现出辩证法物质世界的普遍联系和
  8. 拳皇觉醒服务器维护,拳皇全明星拳魂觉醒手游9月26日更新公告_拳皇全明星拳魂觉醒9月26日更新了什么_玩游戏网...
  9. 【Pre-Finals 2016, Kent Nikaido Contest A】Tetris Puzzle 题解
  10. kmp算法严蔚敏C语言,【菜鸟福音】KMP算法简单理解(从严蔚敏老师的《数据结构》出发)...