赞
踩
这是第二章的习题解答,可能题目的序号有一点错位,改天再修改吧
# 2.1
from __future__ import division
Celsius =eval(raw_input("Enter a degree in Celsius: "))
fahrenheit = (9/5)*Celsius+32
print Celsius , "Celsius is", fahrenheit ,"Fahrenheit"
# 2.2
import math
from __future__ import division
radius,length = eval(raw_input("Enter the radius and length of a sylinder:"))
area = radius*radius*math.pi
volume = area*length
print "The area is",area
print "The volume is",volume
# 2.3
from __future__ import division
mile = eval(raw_input("Enter the value for feet:"))
meter = mile*0.305
# print mile,"feet is",meter,"meters"
print " %.2f feet is %.2f meters" % (mile,meter)
# 2.4
from __future__ import division
p = eval(raw_input("Enter a value in pounds: "))
k =p*0.454
print "%.3f pounds is %.3f kilograms" % (p,k)
# 2.5
from __future__ import division
salary,rate = eval(raw_input("Enter the subtotal and a gratuity rate: "))
gratuity = salary*rate/100
total = gratuity+salary
print "The gratuity is %.3f and the total is %.3f" % (gratuity,total)
# 2.6
from __future__ import division
value = eval(raw_input("Enter a number between 0 and 1000:"))
if 100<=value and value<1000:
sum = value%10+value//10%10+value//100
elif 10<=value and value<100:
sum = value%10+value//10%10
elif value<10:
sum = value
print sum
# 2.7
from __future__ import division
minutes = eval(raw_input("Enter the number of minu
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。