2018年1月8日 星期一

Python: Calculate the sum of three given numbers, if the values are equal then return thrice of their sum

Python: Calculate the sum of three given numbers, if the values are equal then return thrice of their sum

Python Basic: Exercise-18 with Solution

Write a Python program to calculate the sum of three given numbers, if the values are equal then return thrice of their sum.
Sample Solution:-
def sum_thrice(x, y, z):
     sum = x + y + z
     if x == y == z:
      sum = sum * 3
     return sum

print(sum_thrice(1, 2, 3))
print(sum_thrice(3, 3, 3))

========== RESTART: F:/Python_APSC/py-ex-basic-18.py ==========
6
27
>>> 

沒有留言:

張貼留言

OPEN DATA AQI 空氣品質監測網 + NODE-RED

OPEN DATA AQI 空氣品質監測網 + NODE-RED  首頁 - 空氣品質監測網  https://airtw.moenv.gov.tw/ https://data.gov.tw/datasets/search?p=1&size=10&s=_score...