2018年1月8日 星期一

Python: Get a new string from a given string where 'Is' has been added to the front. If the given string already begins with 'Is' then return the string unchanged

Python: Get a new string from a given string where 'Is' has been added to the front. If the given string already begins with 'Is' then return the string unchanged

Python Basic: Exercise-19 with Solution

Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchanged.
Sample Solution:-
def new_string(str):
  if len(str) >= 2 and str[:2] == "Is":
    return str
  return "Is" + str
print(new_string("Array"))
print(new_string("IsEmpty"))
============= RESTART: F:/Python_APSC/py-ex-basic-19.py ===========
IsArray
IsEmpty
>>> 


沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...