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

猜你喜欢

转载自blog.csdn.net/weixin_34293246/article/details/86980117