zoukankan      html  css  js  c++  java
  • Python初级 3 基本数学运算

    一、 四大基本运算操作符

    1 加+

    print(3 + 2)

    2 减-

    print(3 - 2)

    3 乘:*

    print(3 * 2)

    4 除/, //

    print(3 / 2)

    print(3 // 2)

    5 操作符,操作数

    image

    练习:

    print(3 + 2)

    print(3 – 2)

    print(3 * 2)

    print(3 / 2)

    print(3 // 2)

    二、运算顺序

    先乘除,再加减,有括号的先计算括号内的

    print(3 + 5 * 3)

    print(155 – 3 * 5 + 44 / 4)

    三、另外四个操作符:

    1、指数:**

    自乘为一个幂,一个数的多少次幂

    print(3 * 3 * 3 * 3 * 3)

    3的5次幂

    print(3 ** 5)

    print(4 ** 5)

    print(10 ** 2)

    print(10 ** 3)

    print(10 ** 4)

    print(10 ** 5)

    print(3.2 * 10 ** 5)

    2、取余 :%

    print(7%2)

    3、自增 +=

    score = score + 1

    print(score)

    score += 1

    print(score)

    4、自减 –=

    score = score – 1

    print(score)

    score –= score

    print(score)

    练习:

    print(3 * 3 * 3 * 3 * 3)

    print(3 ** 5)

    score = 5

    score –= 1

    print(score)

    四、非常大和非常小

    image

    在计算机中不好表示,e记法:

    3.8e16

    image

     

    附5个练习程序

    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # 加法
    # 输入两个加数,然后输出计算结果
    
    a = float(input("请输入加数:"))
    b = float(input("请输入加数:"))
    print("a + b = {}".format(a, b, a + b))

     
    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # 减法
    # 输入被减数,减数,然后输出计算结果
    
    a = float(input("请输入被减数:"))
    b = float(input("请输入减数:"))
    print("{} - {} = {}".format(a, b, a - b))

    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # 乘法
    # 输入乘数,然后输出计算结果
    
    a = float(input("请输入乘数:"))
    b = float(input("请输入乘数:"))
    print("{} * {} = {}".format(a, b, a * b))
    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # 除法
    # 输入被除数,除数,然后输出计算结果
    
    a = float(input("请输入被除数:"))
    b = float(input("请输入除数:"))
    print("{} / {} = {}".format(a, b, a / b))
    # !/usr/bin/env python3
    # -*- coding: utf-8 -*-
    # 整除
    # 输入被除数,除数,然后输出计算结果(显示整除结果和余数)
    
    a = int(input("请输入被除数(整数):"))
    b = int(input("请输入除数(整数):"))
    print("{} // {} = {}……{}".format(a, b, a // b, a % b))
  • 相关阅读:
    How to implement long running flows, sagas, business processes or similar
    What are long running processes?
    The Microservices Workflow Automation Cheat Sheet
    cget cmake 包管理工具
    buckaroo 试用
    buckaroo 去中心化的c++包管理工具
    What's New In Zeebe: Scaling Zeebe, New Client APIs, Faster Requests, Timestamps, NodeJS Client, and Default Topic is Back!
    Benchmarking Zeebe: An Intro to How Zeebe Scales Horizontally and How We Measure It
    Architecture options to run a workflow engine
    camunda 开源的bpm系统
  • 原文地址:https://www.cnblogs.com/luhouxiang/p/11220242.html
Copyright © 2011-2022 走看看