计算器、tuple操作、dict、其他常用操作

简介:

计算器

#!/usr/bin/env python
#!--coding:utf-8 --
#!shenjie :2018/1/23 22:34
#!@Auther :shenjie
#!@file: 计算器.py
def add(string):
    total=0
    numbers=[]
    numbers+=string.split('+')
    for num in numbers:
        total+=int(num.strip())
    print('{0}={1}'.format(string,total))

def reduce(string):
    result=0
    numbers=[]
    numbers+=string.split('-')
    result=int(numbers[0].strip())
    numbers.pop(0)
    for num in numbers:
        result-=int(num.strip())
    print('{0}={1}'.format(string,result))

def ride(string):
    total=1
    numbers=[]
    numbers+=string.split('*')
    for num in numbers:
        total*=int(num.strip())
    print('{0}={1}'.format(string,total))

def division(string):
    result=0
    numbers=[]
    numbers+=string.split('/')
    result=int(numbers[0].strip())
    numbers.pop(0)
    for num in numbers:
        result /=int(num.strip())
    print("{0}={1}".format(string,result))

if __name__=='__main__':
    print('  ##################################################')
    print('  ###################欢迎来到计算中心##################')
    print('  ##################################################')
    print("1:  加法:a+b+c+d")
    print("2:  减法:a-b-c-d")
    print("3:  乘法:a*b*c*d")
    print("4:  除法:a/b/c/d")
    method=input("Please input num:(1/2/3/4): ")
    if method == "1":
        string=input("请输入您的表达式:")
        add(string)
    elif method == "2":
        string=input("请输入您的表达式:")
        reduce(string)
    elif method == "3":
        string=input("请输入您的表达式:")
        ride(string)
    elif method == "4":
        string=input("请输入您的表达式:")
        division(string)
    else:
        print("您输入的错误,只能输入1/2/3/4")

tuple操作

计算器、tuple操作、dict、其他常用操作

dict

计算器、tuple操作、dict、其他常用操作

计算器、tuple操作、dict、其他常用操作

计算器、tuple操作、dict、其他常用操作

计算器、tuple操作、dict、其他常用操作

计算器、tuple操作、dict、其他常用操作

其他常用操作

计算器、tuple操作、dict、其他常用操作

计算器、tuple操作、dict、其他常用操作










本文转自 iekegz 51CTO博客,原文链接:http://blog.51cto.com/jacksoner/2064426,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
存储 Python
Python中list, tuple, dict,set的区别和使用场景
Python中list, tuple, dict,set的区别和使用场景
|
3月前
|
存储 索引 Python
Python教程:深入了解 Python 中 Dict、List、Tuple、Set 的高级用法
Python 中的 Dict(字典)、List(列表)、Tuple(元组)和 Set(集合)是常用的数据结构,它们各自有着不同的特性和用途。在本文中,我们将深入了解这些数据结构的高级用法,并提供详细的说明和代码示例。
42 2
|
2月前
|
存储 语音技术 Python
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
语音识别,函数综合案例,黑马ATM,/t/t一个对不齐,用两个/t,数据容器入门,数据容器可以分为列表(list)、元组(tuple)、字符串(str)、集合(set)、字典(dict)
|
4月前
|
存储 安全 Java
Python教程第3章 | 集合(List列表、Tuple元组、Dict字典、Set)
Python 列表、无序列表、字典、元组增删改查基本用法和注意事项
81 1
|
存储 数据库 索引
【100天精通python】Day8:数据结构_元组Tuple的创建、删除、访问、修改、推导系列操作
【100天精通python】Day8:数据结构_元组Tuple的创建、删除、访问、修改、推导系列操作
134 0
|
Python
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
1495 0
Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.
|
Scala
Scala常规操作之数组、List、Tuple、Set、Map
Scala常规操作之数组、List、Tuple、Set、Map
169 0
|
索引 Python
Python知识点笔记-列表list、元组tuple和dict类型
Python知识点笔记-列表list、元组tuple和dict类型
128 0
|
索引 Python
python 内置数据结构list、set、dict、tuple(三)
python 内置数据结构list、set、dict、tuple(三)
180 0
|
索引 Python
python 内置数据结构list、set、dict、tuple(二)
python 内置数据结构list、set、dict、tuple(二)
152 0