Comparison: дуруст and нодуруст
In this lesson: you will compare values and meet logical values.
Lesson 7
дуруст and нодурустдуруст and нодурустIn this lesson: you will compare values and meet logical values.
дуруст and нодурустIn this lesson: you will compare values and meet logical values.
The answer to the question "is it true that ...?" is дуруст (yes, true) or нодуруст (no, false). These values are called logical (мантиқӣ):
1чоп(5 > 3);2чоп(2 > 7);3тағ офтобӣ = дуруст;4чоп("Имрӯз офтобӣ:", офтобӣ);
| Sign | Meaning | Example | Result |
|---|---|---|---|
> | greater than | 5 > 3 | дуруст |
< | less than | 5 < 3 | нодуруст |
>= | greater than or equal to | 5 >= 5 | дуруст |
<= | less than or equal to | 4 <= 3 | нодуруст |
=== | equal to | 2 + 2 === 4 | дуруст |
!== | not equal to | 3 !== 3 | нодуруст |
1тағ рақам = хонданиРақам();2чоп("Мусбат:", рақам > 0);3чоп("Ҷуфт:", рақам % 2 === 0);4чоп("Даҳ:", рақам === 10);
10
= and ==== is assignment: тағ х = 5; gives х the value 5.=== is comparison: х === 5 asks "is х equal to five?".Do not mix up these two signs. If you write = in a condition, the playground will warn you.
1тағ ҷавоб = хондан();2чоп(ҷавоб === "Душанбе");
Душанбе
Two strings are equal only if all their letters are the same: "душанбе" is not equal to "Душанбе".
Read two numbers and print the result of the comparison а > б: дуруст or нодуруст.
Input: Two numbers.
Output: дуруст or нодуруст
Read a number and print whether it is even: дуруст or нодуруст.
Input: One number.
Output: дуруст or нодуруст
Read a word and print whether it matches the password сомон: дуруст or нодуруст.
Input: One word.
Output: дуруст or нодуруст