• 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  

     

  • 相关阅读:
    一起Talk Android吧(第四百零一回:如何使用TableLayout布局)
    wsl下svn无法保存密码
    JAVA面试题——关于ValueOf的取值问题
    迁移学习——ResNet152
    ZZNUOJ_C语言1081:n个数求和 (多实例测试)(完整代码)
    MySQL数据库之Java中如何使用数据库【JDBC编程】
    一些框架使用总结
    [SpringBoot] AOP-AspectJ 切面技术
    Conda包依赖侦探:conda inspect命令全解析
    BUG 随想录 - Java: 程序包 com.example.xxx 不存在
  • 原文地址:https://blog.csdn.net/m0_56221131/article/details/125994904