Question Number 46738 by Umar last updated on 30/Oct/18 | ||
$${please}\:{help} \\ $$ $$ \\ $$ $${Write}\:{an}\:{algorithm}\:{that}\:{will}\:{find} \\ $$ $${the}\:{solution}\:{of}\:{the}\:{equation} \\ $$ $$\:\:\:\:\:\:\:\:\:\:{f}\left({x}\right)=\begin{cases}{−{x},\:{when}\:{x}<\mathrm{0}}\\{{x},\:\:\:\:\:{when}\:{x}\geqslant\mathrm{0}}\end{cases} \\ $$ | ||
Commented byhassentimol last updated on 31/Oct/18 | ||
$$\mathrm{I}\:\mathrm{think}\:\mathrm{it}\:\mathrm{may}\:\mathrm{be}\:\mathrm{this}\:: \\ $$ $$\:\:\:\mathrm{ask}\:\mathrm{for}\:\mathrm{x} \\ $$ $$\:\:\:\mathrm{if}\:\mathrm{x}<\:\mathrm{0}\:: \\ $$ $$\:\:\:\:\:\:\:\mathrm{return}\:−\mathrm{x} \\ $$ $$\:\:\:\mathrm{else}\:: \\ $$ $$\:\:\:\:\:\:\mathrm{return}\:\mathrm{x} \\ $$ $$ \\ $$ $$\mathrm{I}\:\mathrm{also}\:\mathrm{think}\:\mathrm{it}\:\mathrm{would}\:\mathrm{be}\:\mathrm{like}\:\mathrm{that}\:\mathrm{on}\:\mathrm{python}\:: \\ $$ $$\mathrm{x}\:=\:\mathrm{float}\left(\mathrm{input}\left(''\mathrm{value}\:\mathrm{of}\:\mathrm{x}\:?''\right)\right) \\ $$ $$\mathrm{if}\:\left(\mathrm{x}<\mathrm{0}\right)\:: \\ $$ $$\:\:\:\:\mathrm{print}\:\left(\left(−\mathrm{1}\right)\ast\mathrm{x}\right) \\ $$ $$\mathrm{else}\:: \\ $$ $$\:\:\:\:\mathrm{print}\left(\mathrm{x}\right) \\ $$ | ||
Commented byUmar last updated on 31/Oct/18 | ||
$${thank}\:{you}\:{sir} \\ $$ | ||