Several conditions
In this lesson: you will check more than two cases and join conditions with the words "and", "or" and "not".
Lesson 9
In this lesson: you will check more than two cases and join conditions with the words "and", "or" and "not".
In this lesson: you will check more than two cases and join conditions with the words "and", "or" and "not".
вагарна агар1тағ хол = хонданиРақам();2агар (хол >= 90) {3чоп("Баҳо: 5");4} вагарна агар (хол >= 70) {5чоп("Баҳо: 4");6} вагарна агар (хол >= 50) {7чоп("Баҳо: 3");8} вагарна {9чоп("Баҳо: 2");10}
85
The conditions are checked from top to bottom. Only the part of the first true condition runs; the others do not.
| Sign | Meaning | Example | When it is дуруст | ||||
|---|---|---|---|---|---|---|---|
&& | and | х > 0 && х < 10 | both conditions are true | ||||
\ | \ | | or | рӯз === 6 \ | \ | рӯз === 7 | at least one is true |
! | not | !борон | борон is false |
1тағ синну = хонданиРақам();2агар (синну >= 7 && синну <= 17) {3чоп("Хонандаи мактаб");4} вагарна {5чоп("Хонандаи мактаб нест");6}
13
A year is a leap year if it can be divided by 4 but not by 100, or if it can be divided by 400:
1тағ сол = хонданиРақам();2агар ((сол % 4 === 0 && сол % 100 !== 0) || сол % 400 === 0) {3чоп("Кабиса");4} вагарна {5чоп("Кабиса нест");6}
2024
Read a number and print Мусбат, Манфӣ or Сифр.
Input: One number.
Output: Мусбат, Манфӣ or Сифр
Read a score (from 0 to 100) and print the grade: 90 or more - 5, 70 or more - 4, 50 or more - 3, anything less - 2.
Input: One number: the score.
Output: The grade.
Read a year and print Кабиса ("leap year") or Кабиса нест. A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400.
Input: One number: the year.
Output: Кабиса or Кабиса нест
Read three sides. If they can make a triangle (each side is shorter than the sum of the other two), print Ҳа, otherwise Не.
Input: Three numbers, each on its own line.
Output: Ҳа or Не