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

沒有留言:

張貼留言

Fultter APP控制 WOKWI ESP32 RFID+LED (使用flutter_windows_3.19.1-stable Visual studio 1.108.2 )

Fultter APP控制 WOKWI ESP32 RFID+LED (使用flutter_windows_3.19.1-stable  Visual studio  1.108.2 ) 1) Android studio 環境設定 2) Visual studio  1.108...