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

in devjr-s20w4 •  last month 

It's another week, and I am glad to be part of this course for the second time; missing out wasn't intentional but for some personal and challenging reasons I opt out for a while. I have read previous courses and I wish I could really understand week2 course, it seems a little bit complex, I am glad that I was able to find an application that can help me testrun my codes too.



Describe your understanding of conditional structures and mention 2 situations of everyday life where you could apply this concept


Conditional structures are programming constructions used to explain situations and the consequences that follow each situation. They involve a conditional term "if," which is a clause that indicates a condition. The consequence or result depends on whether or not each condition is fulfilled. As we program, we don't leave the commands without an end; if a particular condition is not fulfilled, another code must be written to end it; that is the consequence, but somehow it is another fulfillment. Let's take, for instance, a door of height 6 feet that can let only people that are 6 feet tall and below pass it. It is certain that if someoneor something greater than 6 feet wants to pass it, it will not allow, so in this case I can make a program of waiting there since it doesn't meet the criteria.



Real life Situation

This conditional structure is applied in all facets, from the look of things; even natural conditions go with this too.

  • In refrigerators I think they go by this condition, if you turn on the refrigator, it is believe that if it goes below a certain temperature freezing occurs, if it doesn't it is mere cooling.
  • In decision-making, we make use of conditional structures. Most times, when my parents send me to redraw money from the bank, they give me a condition, which also the bank programs into their system too.
  • Check balance If the amount is 100, then redraw 80; if it is 50, then withdraw 40; paraventure: the balance is 50, and I forgot to check the balance; I insert 80 to redraw; even the system will reject my command, which will move me to check the balance. So I would say it is used in financial decision-making and also in automated household appliances.


Create a program that tells the user "Welcome to the room What do you want to do?", if the user writes 1 then it shows a message that says "you have turned on the light", if the user writes 2 then it shows a message that says "you have left the room". Use conditionals


Using the example given I was able to come up with something and the programing language I utilised here is python, the code looks more straight forward.

print("Welcome to the room! What do you want to do?")
print("1. Turn on the light")
print("2. Leave the room")

choice = int(input())

if choice == 1:
    print("You have turned on the light.")
elif choice == 2:
    print("You have left the room.")
else:
    print("Invalid choice. Please enter 1 or 2.")
   
 

After this I had to test the protocols here to see my output and it gave me something admirable

The code and terminal is on left and the display of the code and terminal when I choosed option 1 is on the right



Create a program that asks the user for 4 different ratings, calculate the average and if it is greater than 70 it shows a message saying that the section passed, if not, it shows a message saying that the section can improve


Using the same programming language this is what I was able to come up with.

print("Section Evaluation Program")

rating1 = float(input("Rating 1 (out of 100): "))
rating2 = float(input("Rating 2 (out of 100): "))
rating3 = float(input("Rating 3 (out of 100): "))
rating4 = float(input("Rating 4 (out of 100): "))

average = (rating1 + rating2 + rating3 + rating4) / 4

print("Average Rating: {average:.2f}")

if average >= 70:
    print("Status: Passed")
else:
    print("Status: Can Improve")






This particular image has the program and the outcome when I inserted digits that in calculating will not give me an average greater than 70, it shows can Improve as the consequence of the conditions

For the image above, the terminal show how I insert value that can give me an average greater than equal to or greater than 70 and this is what displayed as the final result, passed👍

I would love my friends @o1eh @drhira and @miftahulrizky to contest via this link

Posted using SteemMobile

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:  

Upvoted! Thank you for supporting witness @jswit.

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

IMG_20240930_084439.png

Congratulations!!🎉🎉 Your post has been upvoted by content seekers using steemcurator05. Continue making creative and quality content on the blog. By @eliany

Loading...

Your post has been rewarded by the Seven Team.

Support partner witnesses

@seven.wit
@cotina
@xpilar.witness

We are the hope!