Numbers and operations
In this lesson: you will do math: add, subtract, multiply and divide.
Lesson 4
In this lesson: you will do math: add, subtract, multiply and divide.
In this lesson: you will do math: add, subtract, multiply and divide.
| Sign | Meaning | Example | Result |
|---|---|---|---|
+ | addition | 7 + 2 | 9 |
- | subtraction | 7 - 2 | 5 |
* | multiplication | 7 * 2 | 14 |
/ | division | 7 / 2 | 3.5 |
1тағ нарх = 12;2тағ шумора = 3;3чоп("Ҳамагӣ:", нарх * шумора, "сомонӣ");4чоп("Нисф:", нарх / 2);
In SomonScript, decimal numbers are written with a dot: 3.5.
It works as in math: first multiplication and division, then addition and subtraction. Brackets change the order:
1чоп(2 + 3 * 4);2чоп((2 + 3) * 4);
1тағ тӯл = 8;2тағ бар = 5;3тағ масоҳат = тӯл * бар;4тағ периметр = 2 * (тӯл + бар);5чоп("Масоҳат:", масоҳат);6чоп("Периметр:", периметр);
5 is a number, "5" is a string. Numbers are added, strings are joined:
1чоп(5 + 5);2чоп("5" + "5");
The result: 10 and 55. Remember this difference: you will need it in the lesson about input.
2,5. In a program, write 2.5.2(3 + 4). Write: 2 * (3 + 4).A day has 24 hours, an hour has 60 minutes, and a minute has 60 seconds. Use arithmetic to work out the number of seconds in a day, and print it.
Input: None.
Output: One number.
A yard is 12 meters long and 7 meters wide. Work out its area and perimeter and print: Масоҳат: … and Периметр: ….
Input: None.
Output: Two lines: the area and the perimeter.
A notebook costs 3 somoni, and a pen costs 2 somoni. We bought 5 notebooks and 4 pens. How many somoni did we pay in total? Print: Ҳамагӣ: ….
Input: None.
Output: Ҳамагӣ: …