PYTHON: 2 books in 1 : Learn python programming for beginners and machine learning by Sanders Willard D
Author:Sanders, Willard D. [Sanders, Willard D.]
Language: eng
Format: epub
Published: 2020-10-27T16:00:00+00:00
The picture above is going to be a good example of what is going to show up when we try to divide by zero. We can change up the message to make it work with what we should see within the code.
When you take a look at this example, your compiler is going to bring up an error, simply because you or the user is trying to divide by zero. This is not allowed with the Python code so it will raise that error. Now, if you leave it this way and you run the program exactly how it is, you are going to get a messy error message showing up, something that your user probably won't be able to understand. It makes the code hard to understand, and no one will know what to do next. A better idea is to look at some of the different options that you can add to your code to help prevent some of the mess from before. You want to make sure that the user understands why this exception is being raised, rather than leaving them confused in the process. A different way that you can write out this code to make sure that everyone is on the same page includes:
x = 10
y = 0
result = 0
try:
result = x/y
print(result)
except ZeroDivisionError:
print(âYou are trying to divide by zero.â)
As you can see, the code that we just put into the compiler is going to be pretty similar to the one that we wrote above. But we did go through and change up the message to show something unless the user raises this exception. When they do get this exception, they will see the message "You are trying to divide by zero" come up on the screen. This isn't a necessary step, but it definitely makes your code easier to use!
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.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9911)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9794)
The Mikado Method by Ola Ellnestam Daniel Brolund(9775)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8292)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7775)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7758)
Grails in Action by Glen Smith Peter Ledbrook(7693)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6779)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6505)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6373)
Kotlin in Action by Dmitry Jemerov(5061)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4314)
Functional Programming in JavaScript by Mantyla Dan(4037)
Solidity Programming Essentials by Ritesh Modi(3975)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3758)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3702)
The Ultimate iOS Interview Playbook by Avi Tsadok(3676)
