3. Input
To read a line the user types, and convert it to a number.
Explanation
Section titled “Explanation”اقرأ("رسالة")(read) shows the message, then reads a line the user types. Its result has the typeنص؟(optional string): a string, orلاشيء(nothing) at the end of input. So give it a fallback:اقرأ("رسالة") والا "".حلل(النص, عدد64)(parse) converts a string to an integer. Its result has the type!عدد64, meaning the conversion may fail, so you handle the failure where it happens.
Example
Section titled “Example”The handbook’s examples run with no input, so اقرأ returned لاشيء here, and والا "" gave an empty string:
اسم = اقرأ("ما اسمك؟ ") والا ""اطبع("أهلاً ", اسم)Common mistakes
Section titled “Common mistakes”حلل(النص, عدد64) has the type !عدد64, because what the user types may not be a number. So give a fallback value for the failure: حلل(اقرأ() والا "", عدد64) والا 0.
اطبع(حلل("ثلاثة", عدد64) + 1)Exit code: 2
In the error catalog: E0399
اطبع((حلل("ثلاثة", عدد64) والا 0) + 1)ن = حلل("٣", عدد64) والا خ: اطبع("ليس عدداً: ", خ) 0اطبع(ن)Exercise
Section titled “Exercise”Read a number from the user and print twice its value; if what they typed is not a number, treat it as 0 with والا (else). (In the solution, the user typed 21.)
Show the solution
ن = حلل(اقرأ("اكتب عدداً: ") والا "", عدد64) والا 0اطبع("ضعفه: ", ن * 2)Input
21See also
Section titled “See also”Builtins: اقرأ and حلل · Error handling