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

in #devjr-s20w23 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 Steemit engagement challenge season 20 week 2 organized by @alejos7ven. The topic of this challenge is about "Variables and types of Data". So let's start the task without any more delay of time.


Your paragraph text_20240918_110650_0000.png

Created With Canva


What are variables and what are they used for?

The variables has a crucial role in programming because they are used to store data in the form of symbols. That is why, the variable acts as a container of data because they can store a huge amount of data in the form of texts, numbers and other symbolic structures. When tha data is stored in the variables, it can be altered or changed right according to our needs and in that way, it can be used during the manufacturing of a program. Let's discuss more about the uses of variables:

1. Data storage:

  • The variables are used to store data in the form of numbers, texts, shapes and objects. That stored data can be used during programming.

2. Unique Name:

  • Each variable has a unique name to distinguish between the variety of variables present in front of a programmer.

3. Make code dynamic:

  • The variables make the codes more dynamic because their value can change which can be used to perform different tasks.

4. Data manipulation:

  • With the help of variables, we can perform various tasks during the building of program like addition, subtraction and solving other mathematical equations.

5. Types of variables:

  • The variables can be found in different types including the integers, strings, boolean and arrays etc.
Assign a type of data to the following variables and explain why: email, phone, working_hours, price_steem, and age.

1. Email:

Data Type: String

Reason: The email is a combination of letters, symbols and numbers which make its sequence. So due to that reason, the email will look more reasonable if it is presented in the form of string.

Example: My email account is [email protected]


2. Phone:

Data Type: String

Reason: The phone number contains special characters like numbers, dashes and parenthesis due to which they are consists of only numbers. So if they are represented as string they will look more suitable.

Example: My phone number is +923424224450.


3. Working_Hours:

Data Type: Integer or Float

Reason: The working can be written as integers or float but mostly they depends on us whatever we want to take the partial hours or complete hours.

Example:08 AM to02 PM


4. Price_Steem:

Data Type: Float or Decimal

Reason: As we know, the Steem is a crypto currency which can fluctuate over the specific periods of time, usually based on the other cryptocurrencies. So the price of steem present in the form of decimal points, in this way, it will more better to represent it in decimal form.

For example: The current price of steem is about $0.16.


5. Age:

Data Type: Integer

Reason: As we know that the age is written in the form of whole numbers without any decimal points. So it will more suitable if we represent age as integers.

Example: My age is 20.


Explain how the following code works?

Define name, last_name as Character;

Print "Enter your name:";
Read name;
Print "Enter your last name:";
Read last_name;

`Print "Hello " name " " last_name ", welcome";`

Step 1: Define name, last_name as Character;

  • This statement declares two variables, name and last_name, which will store character data (strings).

Step 2: Print "Enter your name:";

  • This outputs a prompt to the user asking them to enter their name.

Step 3: Read name;

  • This reads the user's input and assigns it to the name variable.

Step 4: Print "Enter your last name:";

  • This outputs a prompt asking the user to enter their last name.

Step 5: Read last_name;

  • This reads the user's input for the last name and assigns it to the last_name variable.

"Hello " name " " last_name ", welcome"

This will display something like:

Hello abdullahw2, welcome


Develop a pseudo-code to calculate the value in USD of X STEEM.

Algorithm Calculate STEEM Value

Define price_steem, total, amount_steem as Float;

Print "Enter the current price of STEEM in USD:";
Read price_steem;

Print "Enter the amount of STEEM:";
Read amount_steem;

total = amount_steem * price_steem;

Print "The total value in USD is: " total;
EndAlgorithm

Input


IMG_20240918_150112.jpg

Results of output


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, @ahsansharif and @chasad75 to take a part in this amazing challenge.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iP9VDv5a4EtHBpkJfW8Nn7PSXUPJapWuHbag84TFcG78C8dcNHndZWQcoQ8aFmkLxe2x47zw3mg.png


Written by @abdullahw2


ij42VfeLLLL7WCxzYedv2KU7aUqHk3RNyfwHxuumhaYnHDokdbjRLxXkrL7DSe5jzS8jzGDd29gtGG4pvuDJSmxLPGt9GXUQJ72g1AB1fe5qt8DvgzMKW6QWvU4qnL7RCP9XNvs8xoiQDu52RHULmxg9jntMKRVMobRLqEiV5oKKho3MoMJgpUxyzHMbJSmzDNuPnJgSwTrwpTq5YBkjyML1T.gif


Sort:  
Loading...

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

This post has been upvoted/supported by Team 7 via @httr4life. Our team supports content that adds to the community.

image.png

Hi Abdullah I'm already done yesterday thanks for inviting. Your presentation on second task is absolutely well. Everything explain very well. Which tool you use for this last question. I wish you more success.

Hola amigo, has realizado muy bien la tarea, recuerdo que la variable float la usaba en programación C y C++, aunque la clase del profesor, en las definiciones pusieron la variable Real, que basicamente es lo mismo, numeros que contienen decimales.

Has realizado bien tu tarea, por lo que te deseo mucho éxito en tu entrada. Saludos cordiales.

Thank you so much dear friend for visiting my post and leaving a beautiful comment. It is highly appreciated 👍

Coin Marketplace

STEEM 0.31
TRX 0.39
JST 0.061
BTC 96550.85
ETH 3695.88
SBD 4.09