• 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  

     

  • 相关阅读:
    基于第二代 ChatGLM2-6B P-Tuning v2 微调训练医疗问答任务
    HDFS核心原理
    2_企业级Nginx使用-day1
    [剑指Offer] 三种方法求解找出数组中出现次数超过一半的数字
    Android UI freeze分析
    Springboot视图解析与模板引擎~
    word常用的文件格式有哪些?word格式文件删除了怎么恢复
    CAP定理下:Zookeeper、Eureka、Nacos简单分析
    Nginx之sticky第三方模块使用解读
    学习react,复制一个civitai(C站)-更新3
  • 原文地址:https://blog.csdn.net/m0_56221131/article/details/125994904