python嵩天课后思考题_Python语⾔程序设计基础(第⼆版)
嵩天等课后习题答案
第⼀次博⽂ Time:2018年04⽉28⽇ 星期六 11:37
⼆次补充 2018年05⽉02⽇
第⼀章 程序设计基本⽅法 P29
# 1.1字符串的拼接
str1 = input("请输⼊⼀个⼈的名字:")
str2 = input("请输⼊⼀个地点:")
print("世界这么⼤,{}想去{}看看。".format(str1,str2))1234
# 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)1234567
# 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 = ' ')
计算机为什么能识别ascii码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 = ' ')
# ---------1.4 计算1+2!+3!+4!+...+10!------------# sum,tmp = 0,1
for i in range(1,11):
tmp *= i
sum += tmp
print("1+2!+3!+4!+...+10!=",sum)123456
# ---------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)123456access期末考试
# --------1.6 健康⾷谱输出 ------------------------# diet = ['西红柿','⼟⾖','鸡蛋','黄⽠','青菜']
for i in range(5):
for j in range(5):
if (i != j):
print(diet[i],diet[j],sep = '炒')123456
# --------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()1234567891011
# ------1.8 太阳花的绘制 --------------------------# from turtle import *
color('red','yellow')
begin_fill()
forward(200)
left(170)
if abs(pos()) <1:
break
end_fill()
ug编程软件免费下载手机版done()1234567891011
第⼆章 Python程序实例解析
# ---------------温度转换程序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("输⼊格式错误")12345678910
# -----------------循环输⼊----------------------------------#
TempStr = input("请输⼊带有符号的温度值:")
python编程基础教程课后答案
while TempStr[-1] not in ['N','n']:
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:
ajax基础面试题print("输⼊格式错误")
TempStr = input("请输⼊带有符号的温度值:")123456789101112 # --------------------------正⽅形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(1,5):
t.setheading(90*i)
t.done()1234567
# --------------------------六边形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(6):
t.fd(100)
t.seth(60+60*i)
t.done()1234567
# --------------------------叠边形的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(9):
t.fd(150)
t.seth(80+80*i)
t.done()1234567
# --------------------------同切圆的绘制---------------------------------#im import turtle as t
t.pensize(3)
for i in range(4):
t.circle(50+i*10)
t.done()123456
# ----------------------------长度转换------------------#
# 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("输⼊格式错误")1234567891011
import turtle as t
week = ['black','grey','darkgreen','gold','violet','purple','green','red'] 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])
a target属性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()123456789101112131415161718192021
第三章 基本数据类型
天天向上的⼒量
在⼀年中,如果每天进步》》,那么⼀年下来会进步到多少呢?
在⼀年中,如果每天退步》》,那么⼀年下来会倒退到多少呢?
⼀年中每天提升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)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论