Lesson 9

Several conditions

Several conditions

In this lesson: you will check more than two cases and join conditions with the words "and", "or" and "not".

The whole lesson on one page

Several conditions

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}
Input
85

The conditions are checked from top to bottom. Only the part of the first true condition runs; the others do not.

"And", "or", "not"

SignMeaningExampleWhen it is дуруст
&&andх > 0 && х < 10both conditions are true
\\orрӯз === 6 \\рӯз === 7at least one is true
!not!боронборон is false
1тағ синну = хонданиРақам();
2агар (синну >= 7 && синну <= 17) {
3 чоп("Хонандаи мактаб");
4} вагарна {
5 чоп("Хонандаи мактаб нест");
6}
Input
13

Leap year

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}
Input
2024

Task: Sign of a number

Read a number and print Мусбат, Манфӣ or Сифр.

Input: One number.

Output: Мусбат, Манфӣ or Сифр

Task: The grade

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.

Task: Leap year

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 Кабиса нест

Task: Triangle

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 Не