Basic programming course: Lesson #3 Operations

in #devjr-s20w32 months ago
Assalam O Alaikum

Hello dear friends! Welcome to my post. How are you all? I hope you will be doing well by the grace of Almighty Allah. I'm also fine and enjoying my day. Today I'm here to participate in this amazing challenge season 20 week 3 organized by @alejos7ven. The topic of this challenge is about "Basic programming course: Lesson #3 Operations". So let's start without any more delay of time.


Your paragraph text_20240927_104445_0000.png

Created With Canva


Give a brief summary of what arithmetic, comparison and logical operations are for.

All of these, arithmetic, comparison and logical operations has a crucial role in both mathematics and in programming as they are used to manipulate the data in programming and used to do the calculations in mathematics. Without them, we remain unable to perform various tasks while programming. So let's discuss more briefly about each of them:

1. Arithmetic Operations;

The arithmetic operations are used to solve the mathematical equations, do calculations and to manipulate the data during programming. In the arithmetic operations, several operators are used to perform different tasks. Some of these operators are discussed below;

  • Addition + : The addition is represented by + and it is used to add values. For example, if you want to add seven and two it will be, 7 + 2=9.

  • Subtraction - : It is represented by the sign "-" and it is used to subtract first value from second value. For example, if you want to subtract two from seven, it will be 7 - 2 = 5.

  • Multiplication ×: The sign of multiplication is "×" and it is used to multiply one value with another value. For example, if you want to multiply two with seven then it will be, 2 × 7 = 14.

  • Division ÷: The division is used to divide the first value on the second value and it is represented by the symbol "/" and "÷". For example, if you want to divide seven on two the it will be, 7 ÷ 2= 3.5.

  • Modulus %: The modulus is used to bring the reminder by dividing two values and it is represented by the symbol "%". For example, the reminder of 7 % 2 = 1.


IMG_20240927_130855.jpg


IMG_20240927_130933.jpg


Example In python:


IMG_20240927_131432.jpg


IMG_20240927_131442.jpg


2. Comparison Operations:

As from their name, in programming, the comparison operations are used to compare two values and show the boolean results. And the boolean results tell that either the value are equal or not. So we can say that, they have a crucial role in building a program as they help them to make decisions on the basis of relations between the values. Different types of comparison operators are used and let's have a look at them:

  • Equal To (==): It tells us that the two values are equal to each other.

  • Not Equal To (!=): It checks if the two values are not equal to each other.

  • Greater Than (>): That operater checks if the left value is greater than the right value.

  • Less Than (<): It checks if the left value is less than the right value.

  • Greater Than or equal to (>=): That operater checks if the left is greater than or equal to the right value.

  • Less Than or equal to (<=): It checks if the left value is less than or equal to right value.


IMG_20240927_145045.jpg


IMG_20240927_145124.jpg


In Python;


IMG_20240927_145451.jpg

IMG_20240927_145557.jpg


3. Logical Operations:

The logical operations are used to modify and combine boolean values so that we can use the multiple conditions at the same time. They tell us about the condition rather they are true or false. In that way, they help to make informed decisions based on the conditions. Let's have a look at the logical operations:

  • Logical AND (and): If the both operands are true, it turns true if not, it returns to false.

  • Logical OR (or): If one of the operands are true, it returns true, if not it returns to false.

  • Logical NOT (not): That logical operates opposite to the boolean values such as if the value is false it returns true and if it is true it returns false.


IMG_20240927_160708.jpg

IMG_20240927_160743.jpg


In Python:


IMG_20240927_160837.jpg

IMG_20240927_160844.jpg


Make a program that asks the user for 2 numbers and evaluates if both numbers are the same

IMG_20240927_163645.jpg

IMG_20240927_163652.jpg


  • Step 1: number1 = float (input("Enter the first number: "))This line takes input from the user for the first number. The input () function prompts the user with the message "Enter the first number," and float() converts the input to a floating-point number.

  • Step 2: number2 = float (input("Enter the second number: "))Similar to line 1, this line takes input for the second number and converts it to a floating-point number.

  • Step 3: If number1 == number2:This is a conditional statement that checks if the two numbers are equal. The comparison == is used to check if number1 is equal to number2.

  • Step 4: Print("Both numbers are the same.")If the condition on line 4 is true (i.e. the numbers are equal), this line will execute and print the message: "Both numbers are the same."
  • Step 5: If the condition on line 4 is false (i.e. the numbers are not equal) the code under the else block will execute.

  • Step 6: Print ("The numbers are different.") This line will execute if the numbers are not equal, printing the message: "The numbers are different."

Transform the following mathematical expressions into arithmetic expressions on your computer

IMG_6239.jpeg


Expression for Y:

First, subtract 2 from 8, then add 5 and 4, and finally multiply the results.

Y = (8 - 2) × (5 + 4) # Y = 6 × 9
Y = 54 (Multiply 6 by 9 to get 54)

Expression for X:

First, divide 8 by 2, then divide 5 by 5, and finally add the results.

X = (8 / 2) + (5 / 5) X = 4 + 1
X = 5 (Add 4 and 1 to get 5)

Expression for Z:

First, add 4 and 8, then multiply the result by 3, divide by 2, and finally divide by 3.

Z = ((4 + 8) × 3) / 2 / 3 # Z = (12 × 3) / 2 / 3
Z = 36 / 2 / 3 (Multiply 12 by 3 to get 36, then divide by 2)
Z = 18 / 3 Divide 36 by 2 to get 18, then divide by 3
Z = 6 (Divide 18 by 3 to get 6)


IMG_20240927_163652.jpg


Evaluate if the results of the 3 operations are greater than or equal to 0 (>=) and show it on the screen.

Python program that evaluates if the results of the three arithmetic operations (addition, subtraction, and multiplication) are greater than or equal to 0 and displays the results:


IMG-20240927

IMG-20240927

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iP9VDv5a4EtHBpkJfW8Nn7PSXUPJapWuHbag84TFcG78C8dcNHndZWQcoQ8aFmkLxe2x47zw3mg.png

So friends, that was my entry about that challenge and I hope you will enjoy reading it. Now it is a time to say goodbye to everyone and I want to invite my friends @josepha, @jyoti-thelight, @simonnwigwe, @arinaz08 and @paholags to take a part in this amazing challenge.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iP9VDv5a4EtHBpkJfW8Nn7PSXUPJapWuHbag84TFcG78C8dcNHndZWQcoQ8aFmkLxe2x47zw3mg.png


Written by @abdullahw2


ij42VfeLLLL7WCxzYedv2KU7aUqHk3RNyfwHxuumhaYnHDokdbjRLxXkrL7DSe5jzS8jzGDd29gtGG4pvuDJSmxLPGt9GXUQJ72g1AB1fe5qt8DvgzMKW6QWvU4qnL7RCP9XNvs8xoiQDu52RHULmxg9jntMKRVMobRLqEiV5oKKho3MoMJgpUxyzHMbJSmzDNuPnJgSwTrwpTq5YBkjyML1T.gif


Sort:  
Loading...

TEAM 5

Congratulations! This post has been upvoted through steemcurator07. We support quality posts, good comments anywhere, and any tags.


image.png

Curated by : @damithudaya

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

Coin Marketplace

STEEM 0.31
TRX 0.39
JST 0.062
BTC 96632.04
ETH 3716.71
SBD 4.12