Back

Sanskar

Keen Learner and Exp... • 2d

Day 15 of learning python as a beginner. Topic: Error Handling. A lot of amazing people have suggested me that I should learn error handling in order to tackle unexpected situation which may arise. I created this basic calculator which can perform arithematic operations, generate a table, and convert units. My initial plan was to use error handling in my previous programs however I put it on hold and created a new program (I will still be using error handling in my previous code as well). Error handling consists of two main functions: try: this will run when the there is no error in the user input or program i.e the program runs as expected. except: this gets executed whenever an error arise however we can use this to raise custom error ex: print("Invalid Input") rather than those long red error lines. we can also use "raise" function to create a custom error ex: raising value error when a user typed a string where he was supposed to enter an integer. raise essentially stops the function when an error arsie however the program executes completely when using try and except. I first begin by creating a specific class dedicated for a specific feature like arithematic operation, generate table and unit converter. Then I called these functions using if elif and else ladder (can someone please tell me how to call these functions in a better way as I feel like using so many if elif and else isn't very efficient). I have attached the code in two parts (classes and script) because it was to long to come under one image. And of course everything will work fine if there is no errors in input however I have only added the result where error handling is involved. I will soon be publishing my codes on github so that all of you can run it and learn and also suggest potential changes and bugs etc. Of course after completing my little gift for you all amazing people which I told you about in my yesterday's post (I don't know its effect on your life however I am trying my best). I warmly welcome all the suggestions and questions regarding my code which will help me improve my knowledge and code structure and execution.

Reply
3

More like this

Recommendations from Medial

Sanskar

Keen Learner and Exp... • 12d

Day 5 of learning python as a beginner. Topic: Functions On my previous day post many people shared their github where I was introduced to def functions and since then I started learning more about def functions. Thank you all those people who are

See More
Reply

DK

 • 

Ride • 1y

Reply
3

Sanskar

Keen Learner and Exp... • 6d

Day 11 of learning python as a beginner. Topic: creating journal entry program using file I/O. I got a little sidleline from my original plan of editing my to-do list program and created an entirely new program this time for writing a daily journal

See More
Reply
1
10
Image Description
Image Description

Yash

YoYo • 8m

I know the basics of python language like functions, file handling, stack, etc what should I learn in python to get the fastest internship or job as freshers

4 Replies
2

Sumit nyayadhish

Build that help • 12m

I am getting this error while submitting my profile information @mefial

Reply
2
Image Description

Shivansh Tiwari

I am financial analy... • 1y

Hello I am professional trader 5 year experience I am started a new business for handling a demat account and make a profit who interested so comment me My portfolio

1 Reply
2
Image Description
Image Description

hiboka sumi

Building India’s fir... • 7m

I can’t showcase my Idea. It shows error whenever I try to post. Help Medial

5 Replies
3
Image Description
Image Description

Vivek Sorathiya

Hey I am on Medial • 1y

Is it only me that whenever i start some project , i would run into problems that are so silly and insignificant that searching the solution for it would give anyone second hand embarrassment. For Ex. before even writing the first line of code, i wo

See More
3 Replies
9
Image Description
Image Description

Kumar Arun K

.. • 1m

Why am i unable to showcase my startup it’s popping up an error 😭

10 Replies
1

Download the medial app to read full posts, comements and news.