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
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.
Hello! Python by Anthony Briggs(9372)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9343)
The Mikado Method by Ola Ellnestam Daniel Brolund(9307)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7851)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7402)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7322)
Grails in Action by Glen Smith Peter Ledbrook(7295)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7116)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5957)
Kotlin in Action by Dmitry Jemerov(4637)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3883)
Functional Programming in JavaScript by Mantyla Dan(3723)
Learning Java by Patrick Niemeyer & Daniel Leuck(2871)
Mastering Python for Finance by Weiming James Ma;(2838)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2835)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2600)
Windows APT Warfare by Sheng-Hao Ma(2592)
Mastering Java 9 by Dr. Edward Lavieri(2572)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2558)