Python Crash Course: The Ultimate Step-By-Step Guide to Learn, Understand, and Master Python Programming and Computer Coding Language (From Beginners to Advanced) by Deep James

Python Crash Course: The Ultimate Step-By-Step Guide to Learn, Understand, and Master Python Programming and Computer Coding Language (From Beginners to Advanced) by Deep James

Author:Deep, James [Deep, James]
Language: eng
Format: epub
Published: 2020-09-10T16:00:00+00:00


The If Conditional Statements

The first thing we are going to look at is regular if statement. This keeps things simple and will ensure that we are set and ready to handle some of the basics of these conditional statements. This one is based on the idea that the answer the user gives is either true or it is false depending on what conditions you have set. If the user adds in input that the program is going to see as true, then your program will see this and will continue on to the next step. But if the user does put in an answer that is seen as false for that part of the code, then the program will just end because nothing is set up to handle this issue along the way. As we can see here already, there is the potential for some problems when you are working with this kind of coding. But we are still going to take a quick look at this to see how it works and to get the basic idea of these conditional statements, and then move on to how we can change things on to fix this issue. A good example of how the, if the statement is able to work, will be below:

age = int(input(“Enter your age:”))

if (age <=18):

​ print(“You are not eligible for voting, try next election!”)

print(“Program ends”)

Let’s explore what is going to happen with this code when you put it into your program. If the user comes to the program and puts that they are younger than 18, then there will be a message that shows up on the screen. In this case, the message is going to say “You are not eligible for voting, try next election!” Then the program, as it is, is going to end. But what will happen to this code if the user puts in some age that is 18 or above?

With the if statement, nothing will happen if the user says that their age is above 18. The if statement just has one option and will focus on whether the answer that the user provides is going to match up with the conditions that you set with your code. The user has to put in that they are under the age of 18 with the if statement in this situation, or you won’t be able to get the program to happen again .

As we have already mentioned with this one, the if statement could end up causing us a few problems when we are coding. You want to make sure that the user is able to put in any answer that is the best for them, not the “right” answer, and you want to make sure that the program you are writing is still going to be able to respond and give some kind of answer to the user along the way. Some of the users who come to your website or program will have an age that is higher than 18,



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.