python入门教程 3

Tip Calculator


 

1 把变量meal的值设置为44.50

[python] 

#Assign the variable meal the value 44.50 on line 3!  

meal = 44.50  

 

1 把变量tax的值设置为6.75%     

[python]  

meal = 44.50  

tax = 6.75/100  

 

1 设置tip的值为15%   

[python]  

#You're almost there! Assign the tip variable on line 5.  

meal = 44.50  

tax = 0.0675  

tip = 0.15  

 

1 把变量meal的值设置为meal+meal*tax

[python]  

#Reassign meal on line 7!  

meal = 44.50  

tax = 0.0675  

tip = 0.15  

meal = meal+meal*tax  

 

设置变量total的值为meal+meal*tax

[python]  

#Assign the variable total on line 8!  

meal = 44.50  

tax = 0.0675  

tip = 0.15  

meal = meal + meal * tax  

total = meal + meal * tip  

print("%.2f" % total)  

Python 入门教程 3 ---- Strings and Console Output

15 Python里面还有一种好的数据类型是String

16一个String是通过'' 或者 ""包成的串

     3 设置变量brian值为"Always look on the bright side of life!"

[python]  

#Set the variable brian on line 3!  

brian = "Always look on the bright side of life!"  

 

1 练习

       1 把变量caesar变量设置为Graham

       2 把变量praline变量设置为john

       3 把变量viking变量设置为Teresa

[python]  

#Assign your variables below, each on its own line!  

caesar = "Graham"  

praline = "John"  

viking = "Teresa"  

#Put your variables above this line  

print caesar  

print praline  

print viking  

 

17 Python是通过\来实现转义字符的

    2 练习把'Help! Help! I'm being repressed!' 中的I'm中的'进行转义

[python]  

#The string below is broken. Fix it using the escape backslash!  

'Help! Help! \'\m being repressed!'  

 

18 我们可以使用""来避免转义字符的出现

    2 练习: 把变量fifth_letter设置为MONTY的第五个字符

[python]  

""" 

The string "PYTHON" has six characters, 

numbered 0 to 5, as shown below: 

 

+---+---+---+---+---+---+ 

| P | Y | T | H | O | N | 

+---+---+---+---+---+---+ 

  0   1   2   3   4   5 

 

So if you wanted "Y", you could just type 

"PYTHON"[1] (always start counting from 0!) 

"""  

fifth_letter = "MONTY"[4]  

  

print fifth_letter  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值