[转载]Python语⾔程序设计基础(第⼆版)嵩天等课后习题答
案
第⼀次博⽂ Time:2018年04⽉28⽇ 星期六 11:37 ⼆次补充 2018年05⽉02⽇ 第⼀章 程序设计基本⽅法 P29
# 1.1字符串的拼接
str1 = input("请输⼊⼀个⼈的名字:")
str2 = input("请输⼊⼀个地点:")
print("世界这么⼤,{}想去{}看看。".format(str1,str2))
# 1.2整数序列求和
n = input("请输⼊⼀个整数N:")
sum = 0
for i in range(int(n)):#或者调和函数eval(n)
print(i,end = ' ')
sum = sum + i+1
print("1到N求和结果为:",sum)
# 1.3 9*9乘法表
# 版本⼀
for i in range(1,10):
for m in range(1,i+1):
sum = i*m
if m < i:
if sum < 10:
print(m,'*',i,"= {}".format(sum),end = ' ')
else:
print(m,'*',i,'=',sum,end = ' ')
else:
print(m,'*',i,'=',sum)
# 版本⼆
for i in range(1,10):
for j in range(1,i+1):
print("{} * {} = {:2}".format(j,i,i*j),end = ' ')
print('')
# ---------1.4 计算1+2!+3!+4!+...+10!------------#
for i in range(1,11):
tmp *= i
sum += tmp
print("1+2!+3!+4!+...+10!=",sum)
# ---------1.5 猴⼦吃桃问题 ----------------------# # list(range(5,0,-1)) ----- [5, 4, 3, 2, 1]
n = 1
for i in range(5,0,-1):
n = (n+1)*2 #n = (n+1)<<1 左移⼀位乘以2 print(n)
# --------1.6 健康⾷谱输出 ------------------------# diet = ['西红柿','⼟⾖','鸡蛋','黄⽠','青菜']
for i in range(5):
for j in range(5):
if (i != j):
print(diet[i],diet[j],sep = '炒')
# --------1.7 绘制五⾓星 --------------------------# from turtle import *
##fillcolor("red")
color('red','yellow') #color('线条颜⾊','填充颜⾊') begin_fill()
while True:
forward(200)
right(144)
if abs(pos()) < 1:
break
end_fill()
# ------1.8 太阳花的绘制 --------------------------# from turtle import *
color('red','yellow')
begin_fill()
while True:
forward(200)python编程基础教程课后答案
if abs(pos()) <1:
break
end_fill()
done()
第⼆章 Python程序实例解析
html5怎么用jsp# ---------------温度转换程序1.1 P35-------------------------#
TempStr = input("请输⼊带有符号的温度值:")
if TempStr[-1] in ['F','f']:
C = (eval(TempStr[0:-1]) - 32) / 1.8
print("华⽒温度{}转换为摄⽒度温度是:{:.2f}C".format(TempStr,C)) elif TempStr[-1] in ['C','c']:
F = eval(TempStr[0:-1])*1.8 + 32
print("摄⽒温度{}转换为华⽒温度是:{:.2f}F".format(TempStr,F)) else:
print("输⼊格式错误")
# -----------------循环输⼊----------------------------------#
TempStr = input("请输⼊带有符号的温度值:")
while TempStr[-1] not in ['N','n']:
wordpress下载安卓版if TempStr[-1] in ['F','f']:
C = (eval(TempStr[0:-1]) - 32) / 1.8
print("华⽒温度{}转换为摄⽒度温度是:{:.2f}C".format(TempStr,C)) elif TempStr[-1] in ['C','c']:
F = eval(TempStr[0:-1])*1.8 + 32
print("摄⽒温度{}转换为华⽒温度是:{:.2f}F".format(TempStr,F))
else:
print("输⼊格式错误")
TempStr = input("请输⼊带有符号的温度值:")
# --------------------------正⽅形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(1,5):
t.fd(100)
t.setheading(90*i)
# --------------------------六边形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(6):
t.fd(100)
t.seth(60+60*i)
t.done()
# --------------------------叠边形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(9):
t.fd(150)
t.seth(80+80*i)
t.done()
# --------------------------同切圆的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(4):
t.circle(50+i*10)
t.done()
# ----------------------------长度转换------------------#
# 1⽶ = 39.37英⼨
le = input()
if le[-1] in ['M','m']:
temp = eval(le[0:-1]) * 39.37
print("{:.3f}in".format(temp))
elif le[-2:] in ['in','IN']:
temp = eval(le[0:-2]) / 39.37
汇编语言指令集合print("{:.3f}m".format(temp))
else:
print("输⼊格式错误")
# ------------------------多彩蟒蛇的绘制---------------------------------# import turtle as t
def drawSnake(r,angle,length):
t.seth(-40)
for i in range(length):
t.pencolor(week[i%8])
t.circle(r,angle)
t.pencolor(week[(i+1)%8])
t.circle(-r,angle)
t.circle(r,angle/2)
t.fd(40)
t.circle(16,180)
t.fd(40*2/3)
t.setup(650,350)
t.penup()
t.fd(-250)
t.pendown()
t.pensize(25)
drawSnake(40,80,9)
t.done()
滚动条默认在最下面第三章 基本数据类型 天天向上的⼒量 在⼀年中,如果每天进步》》,那么⼀年下来会进步到多少呢? 在⼀年中,如果每天退步》》,那么⼀年下来会倒退到多少呢?
⼀年中每天提升0.001:1.44,⼀年中每天能⼒下降0.001:0.69⼀年中每天提升0.005:6.17,⼀年中每天能⼒下降0.005:0.16⼀年中每天提升0.01:37.78,⼀年中每天能⼒下降0.01:0.03向上5天向下2天的⼒量:4.63。⼯作⽇多努⼒每天的努⼒应达到:0.019
# 1.1 每天的改变在千分之⼀ P74
import math
dayup = math.pow((1+0.001),365)
daydown = math.pow((1-0.001),365)
一对象的图片表情包
print("⼀年中每天提升0.001:{:.2f},⼀年中每天能⼒下降0.001:{:.2f}".format(dayup,daydown))
import math
dayup = math.pow((1+0.005),365)
daydown = math.pow((1-0.005),365)
print("⼀年中每天提升0.005:{:.2f},⼀年中每天能⼒下降0.005:{:.2f}".format(dayup,daydown))
#1.3 每天的改变在百分之⼀
import math
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论