2018年1月8日 星期一

Python: Sum of three given integers. However, if two values are equal sum will be zero

Python: Sum of three given integers. However, if two values are equal sum will be zero

Python Basic: Exercise-33 with Solution

Write a Python program to sum of three given integers. However, if two values are equal sum will be zero.
Sample Solution:-
def sum(x, y, z):
    if x == y or y == z or x==z:
        sum = 0
    else:
        sum = x + y + z
    return sum

print(sum(12, 11, 12))
print(sum(3, 12, 12))
print(sum(12, 22, 22))
print(sum(11, 12, 13))

============ RESTART: F:/Python_APSC/py-ex-basic-33.py ===========
0
0
0
36
>>> 

沒有留言:

張貼留言

Wokwi ESP32 Simulator : ESP32 + LED +MQTT+ Node-RED Dashboard

 Wokwi ESP32 Simulator : ESP32 +  LED +MQTT+ Node-RED Dashboard  WOKWI ESP32程式 // Create an MQTT Connection // TCP Connection // import the ...