zoukankan      html  css  js  c++  java
  • python Days1

    python代码编写使用英文输入法

    控制台的读取和输入:

    input输入进去的是字符串

    eval

    在jupyter用shift+tab跳出解释文档

    运算符:

    +:加

    -:减

    *:乘

    /:除

    //:整除

    **:指数幂

    %:取余

    增强型赋值运算:

    +=:自加

    -=:自减

    *=:自乘

    /=:自除

    代码:

    celsius=float(input('Enter a degree in Celsius:'))
    fahrenheit = (9 / 5) * celsius + 32
    print("{0} Celsius is {1} Fahrenheit" .format(celsius,fahrenheit))

    代码:

    import math
    radius,length=eval(input('Enter the radius and length of a cylinder:'))
    area = radius **2 * math.pi
    volume = area * length
    print("The area is {0}".format("%.4f"% area))
    print("The volume is {0}".format("%.1f"% volume))

    代码:

    feet=float(input('Enter a value for feet:'))
    meters=feet * 0.305
    print("{0} feet is {1} meters".format(feet,meters))

    代码:

    water=float(input('Enter the amount of water in kilograms:'))
    initialtemperature=float(input('Enter the initial temperature:'))
    finaltemperature=float(input('Enter the final temperature:'))
    Q = water * (finaltemperature - initialtemperature) * 4184
    print("The energy needed is ",Q)

    代码:

    balance,interestrate=eval(input('Enter balance and interest rate (e.g., 3 for 3%):'))
    interest=balance * (interestrate / 1200)
    print("The interest is {0}".format("%.5f"%interest))

    代码:

     v0,v1,t=eval(input('Enter v0,v1,and t:'))
    a=(v1 - v0) / t
    print("The average acceleration is {0}" .format("%.4f"% a))

    代码:

    number=float(input("Ener the monthly saving amount :"))
    number1=0
    for i in range(6):
        number1=(number+number1) * (1 + 0.00417)
    print("After the sixth month,the account value is {0}".format("%.2f"% number1))

    代码:

     number=float(input("Enter a number between 0 and 1000:"))
    bai=int(number/100)
    shi=int(number/10%10)
    ge=int(number%10)
    he=bai+shi+ge
    print("The sum of the digits is ",he)

    体会:

    通过初时Python以及对他的语言元素的认识,对于python有了很深的印象

  • 相关阅读:
    Docker基本命令及工作原理
    Docker安装
    linux命令
    MTPuTTy使用
    SpringBoot--swagger搭建、配置及使用
    idea使用技巧
    Idea插件
    IDEA开发工具使用 git 创建项目、拉取分支、合并分支
    git命令
    javbus爬虫-老司机你值得拥有
  • 原文地址:https://www.cnblogs.com/huangchuan/p/11272641.html
Copyright © 2011-2022 走看看