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

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...