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

沒有留言:

張貼留言

RFID TI 培訓影片系列

RFID TI 培訓影片系列  https://www.ti.com/zh-tw/video/series/rfid.html 培訓影片系列 RFID 隨著創新技術日益發展,RFID 和 RF 術語越來越容易讓人混淆。本訓練系列詳細介紹了使用案例、權衡技術優缺點,讓您清楚知道該選...