python3测试工具开发快速入门教程3序列小结与文本处理

[雪峰磁针石博客]python3快速入门教程

预计本章简稿完成日期: 2018-07-18

变量与赋值

自己实现求最大值。

代码:

#!python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author:    xurongzhong#126.com wechat:pythontesting qq:37391319
# 技术支持 钉钉群:21745728(可以加钉钉pythontesting邀请加入) 
# qq群:144081101 591302926  567351477
# CreateDate: 2018-6-12 
# mymax2.py
# Write max function without built-in max().

def mymax2(x, y):
    """Return larger of x and y."""
    largest_so_far = x
    if y > largest_so_far:
        largest_so_far = y
    return largest_so_far
    
def main():
    print("MyMax: Enter two values to find the larger.")
    first = float(input("First value: "))
    second = float(input("Second value: "))
    print("The larger value is", mymax2(first, second))
    
main()

执行:

#!python
$ python3 mymax2.py 
MyMax: Enter two values to find the larger.
First value: 3
Second value: 89
The larger value is 89.0

注意赋值是=,判断是否等于是==。

python的基础数据类型有bool、float、int、str

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容