1.18.2013 #Practical Programming #1

本文提供了《实用编程》第二章的习题解答,包括表达式计算、温度单位转换、里程单位换算等内容,适合初学者练习Python编程基础。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# Practical Programming.
# exercises - 2.10

# 1 - Expressions
# ------------------------------------------------------------------------------

#print '#1'
#print 'a)', '9 - 3 =', 9 - 3
#print 'b)', '8 * 2.5 =', 8 * 2.5
#print 'c)', '9 / 2 =', 9 / 2
#print 'd)', '9 / -2 =', 9 / -2
#print 'e)', '9 % 2 =', 9 % 2
#print 'f)', '9 % -2 =', 9 % -2
#print 'g)', '-9 % 2 =', -9 % 2
#print 'h)', '9 / -2.0 =', 9 / -2.0
#print 'i)', '4 + 3 * 5 =', 4 + 3 * 5
#print 'j)', '(4 + 3) * 5 =', (4 + 3) * 5

# 2 - Unary minus & Unary plus
# ------------------------------------------------------------------------------

#print '#2'
#x = -17
#print 'x =', x
#print '+x =', +x
#print '+5 =', +5

# 3 - Celsius to Fahrenheit
# ------------------------------------------------------------------------------

#temp = 24
#print 'temp former:', temp
#temp = temp * 1.8 + 32
#print 'temp now:', temp

# 4 - Assignment
# ------------------------------------------------------------------------------

#x = 10.5
#y = 4
#print 'x =', x, '\ny =', y
#x = x + y
#print 'x now:', x
#print 'y now:', y

# 5 - A statement
# ------------------------------------------------------------------------------

#x = 3
#print 'x =', x
#x += x - x
#print 'x now:', x, '\n'
#print 'x += x - x \'s bullet list'
#print '--------------------------'
#print '1. x = 3'
#print '2. x - x = 3 - 3 = 0'
#print '3. x = x + 0 = 3 + 0 = 3'

# 7 - convert_mileage
# ------------------------------------------------------------------------------

# lp100km    =    liters per 100 km
# kmpm       =    mpg = miles per gallon
# lpg        =    liters per gallon (US) = 3.785411784
# kmpm       =    kilometers per mile = 1.609344

#lpg = 3.785411784
#kmpm = 1.609344
#def convert_mileage(miles_per_gallon):
    #mpg = miles_per_gallon
    #return (100 * lpg)/(kmpm * mpg)

#miles_per_gallon = float(raw_input('Enter miles_per_gallon: '))
#print convert_mileage(miles_per_gallon), 'liters_per_100kilometers'

# 9 - liters_needed
# ------------------------------------------------------------------------------

#lpg = 3.785411784
#kmpm = 1.609344
#def convert_mileage(miles_per_gallon):
    #mpg = miles_per_gallon
    #return (100 * lpg)/(kmpm * mpg)


#def liters_needed(distance_in_kilometers, gas_mileage):
    #gas_needed_in_liters = (distance_in_kilometers / 100.0) * convert_mileage(gas_mileage)
    #return gas_needed_in_liters

#print liters_needed(150, 30)
#print liters_needed(100, 30)

# 10 - built-in
# ------------------------------------------------------------------------------

#print pow(3, 7)
#print int(34.7)
#print round(34.7)
#print float(abs(-86))

Practical Programming第二章习题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值