預(yù)計(jì)本章簡(jiǎn)稿完成日期: 2018-07-18
變量與賦值
自己實(shí)現(xiàn)求最大值。
代碼:
#!python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: xurongzhong#126.com wechat:pythontesting qq:37391319
# 技術(shù)支持 釘釘群:21745728(可以加釘釘pythontesting邀請(qǐng)加入)
# 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()
執(zhí)行:
#!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的基礎(chǔ)數(shù)據(jù)類(lèi)型有bool领舰、float返帕、int桐玻、str