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
>>> 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...