Basic programming course: Lesson #4 Control structures. Part 1. Conditionals.

in devjr-s20w4 •  last month 

Today, I will write a teaching assignment for @alejos7ven sir in Week 04 of the Teaching Engagement Challenge Session 20. The subject is Basic Programming Course: Lesson #4 Control Structures. Part 1. Conditionals. I hope everyone will find this lesson engaging and informative.

Basic programming course Control structures. Part 1. Conditionals..png

Designed in Canva

Understanding Conditional Structures and Everyday Applications

Conditional structures are fundamental programming concepts that allow a program to make decisions based on certain conditions. Just as humans make decisions based on different scenarios, conditional structures enable computers to evaluate conditions and execute specific blocks of code accordingly.

Everyday Situations for Conditional Structures

  1. Smart Home Lighting:
    Imagine you have a smart home lighting system. You want the lights to turn on automatically when someone enters a room and turn off when the room is empty. Here’s how you can think about it:

    • If motion is detected (someone enters the room), then turn on the lights.
    • Else (no motion is detected), keep the lights off.
  2. Online Shopping Cart:
    When shopping online, the website needs to decide whether you are eligible for free shipping. The conditions might be:

    • If the total purchase amount is greater than $50, then free shipping is applied.
    • Else, standard shipping charges are applied.

Programming Task 1: Room Actions

Let's create a program that asks the user what they want to do upon entering a room. If the user writes 1, it shows a message that says "You have turned on the light." If the user writes 2, it shows a message that says "You have left the room."

# Define the variable to store the user's choice
Define choice As Integer;

# Ask the user what they want to do
Print "Welcome to the room. What do you want to do?";
Print "Press 1 to turn on the light.";
Print "Press 2 to leave the room.";
Read choice;

# Evaluate the user's choice
If (choice == 1) Then
    Print "You have turned on the light.";
ElseIf (choice == 2) Then
    Print "You have left the room.";
Else
    Print "Invalid choice. Please press 1 or 2.";
EndIf

Programming Task 2: Calculate Average Rating

Now, let's create a program that asks the user for four different ratings, calculates the average, and shows a message based on whether the average is greater than 70 or not.

# Define the variables to store the ratings and the average
Define rating1, rating2, rating3, rating4 As Integer;
Define average As Float;

# Ask the user for four different ratings
Print "Enter the first rating:";
Read rating1;
Print "Enter the second rating:";
Read rating2;
Print "Enter the third rating:";
Read rating3;
Print "Enter the fourth rating:";
Read rating4;

# Calculate the average
average = (rating1 + rating2 + rating3 + rating4) / 4;

# Evaluate the average and display the appropriate message
If (average > 70) Then
    Print "You have passed the section.";
Else
    Print "You can improve in this section.";
EndIf

Conclusion

Conditional structures are powerful tools in programming, enabling computers to make decisions based on varying conditions. By understanding and applying these concepts, we can create more dynamic and responsive programs. The homework tasks provided demonstrate practical applications, from simple room actions to evaluating average ratings, highlighting the versatility and importance of conditional structures in everyday programming scenarios.

My Invited Steemit Friends
1 @memamun
2 @shahariar1
3 @max-pro

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...

Your post has been rewarded by the Seven Team.

Support partner witnesses

@seven.wit
@cotina
@xpilar.witness

We are the hope!