Basic programming course: Lesson #2 - Variables and Types of Data.

in #devjr-s20w219 hours ago


1000316107.jpg
Variables and type of Data

Hi everyone!

Greetings and welcome to this week's engagement challenge. Ready and enthusiastic, we are on it again to learn some basics about programming. Nice work done by the team for bringing to us this amazing topic. Without further ado, I will go straight to completing the task for this week.


1

What are variables and what are they used for?


In programming, variables takes the form of containers that hold values. These values can be numbers, text, or even other variables. For example, you might have a variable called age that holds the number 30. Or you could have a variable called name that holds the text "Alice".

Why do we use variables?

  • Flexibility: Variables allow us to store and manipulate data dynamically. Instead of hardcoding values directly into our code, we can use variables to make our programs more adaptable.

  • Organization: By giving meaningful names to variables, we can make our code easier to understand and maintain.

  • Efficiency: Variables can help us avoid redundant calculations. Take for example, supposed we need to use the same value multiple times in a given program, we can store it in a variable and give reference to it by its name.

Come to visualize it this way: Variables stands as the building blocks of programming. They help us create dynamic and efficient applications.

Example:

ALGORITHM DATAS
DECLARE length, width, area ;
READ length, width ;
area = length * width ;
PRINT "The area of the rectangle is equal to :", Area ;
ENDALGORITHM


2

Assign the data type use for the following variables and give reasons: email, phone, working_hours, price_steem, and age.


1• Email:

  • Data type: character
  • Reason: An email address is a sequence of characters that's ; letters, numbers, symbols For example [email protected]. They typically contains a combination of these. Strings are used to represent text data form.

2• Phone:

  • Data type: character /integer depending on mode of use
  • Reason: While phone numbers can be represented as numbers, they often include special characters for instance; hyphens, parentheses and may have varying formats. Therefore, a string is a versatile choice.

3• working_hours:

  • Data type: Integer or real
  • Reason: Working hours typically represent a numerical quantity, such as 8 hours or 40 hours per week. Integers are suitable for whole numbers, while reals can be used for decimal values if necessary.

4• Price_steem:

  • Data type: *real or Decimal
  • Reason: Prices often involve decimal points (e.g., $12.99). Floats or decimals are appropriate for representing numerical values with fractional parts.

5. age:

  • Data type: Integer
  • Reason: Age is typically represented as a whole number. Integers are suitable for storing whole numerical values.

3.

Explain how the following code works:


1000316111.png


1• Define name, last_name as Character

Explanation: Declare the variables name and last_name to be store as a text.

2• Print "Enter your name:"

Explanation: This will Display a message prompting the user to enter his/her first name.

3• Read name:

Explanation: The program pause for the user to enter his/her first name and stores this entry in the variable name, before moving to the next step

4• Print "Enter your last name:"

Explanation: This will Displays a message requesting the user to enter his/her last name.

5• Read last_name:

Explanation: The program pause for the user to input his/her last name and stores this entry in the variable last_name.

6• Print "Hello " name " " last_name ", welcome"

Explanation :This line constructs a greeting message using the stored values of "name" and "last_name." It prints "Hello" followed by the user's first name, a space, their last name, and an exclamation mark.

7• EndAlgorithm:

Explanation: This indicates the end of the algorithm or program.


4

Develop a pseudo-code to calculate the value in USD of X STEEM. For this you can rely on this algorithm:


Start by lunching pseint application.

1000316134.png

Then proceed by writing the code which will help us calculate our steem value in USD as shown above. And the. Execute.

1000316133.png

This is our final result.

I hereby invite a following persons to join me participate in this contest. @chant, @simonnwigwe, and @fombae


Credit to: @rafk


Sort:  

I wish I could take the programming course but it is not my thing 🌚🌚. I wish you all the best for your entry 🫶.

Haha. We will teach you after learning too.

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.028
BTC 63099.80
ETH 2455.59
USDT 1.00
SBD 2.58