资讯详情

python入门教程 3

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)  

     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  

 

    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!'  

 

    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  

 

标签: viking氧化膜电阻器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台