2018年1月8日 星期一

Python: Sum of two given integers. However, if the sum is between 15 to 20 it will return 20

Python: Sum of two given integers. However, if the sum is between 15 to 20 it will return 20

Python Basic: Exercise-34 with Solution

Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it will return 20.
Sample Solution:-

def sum(x, y):
    sum = x + y
    if sum in range(15, 20):
        return 20
    else:
        return sum

print(sum(10, 6))
print(sum(10, 2))
print(sum(10, 12))

========== RESTART: F:/Python_APSC/py-ex-basic-34.py =============
20
12
22
>>> 

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...