Few important things to note about try and exception method: 1. We can use else clause with exception handling. try: result = 100 / 2 except ZeroDivisionError: print(f"Division Error") else: print("Result is", result) 2. Using the finally clause in exception handling try: result = 10 / 0 except ZeroDivisionError: print("Division by zero!") finally: print("This block of code will always execute.") 3. Raising exceptions using raise try: raise ValueError("This is a custom error message.") except ValueError as e: print("An error occurred:", str(e))
Error dikhane ka stylish way 😁😁😁😁😁😁😁😁 # My code box=[] while(True): try: num = int(input("Enter num:")) for i in range(1,num): print(i) x=[2,3,4,5] print(x[num]) break except IndexError : print("IndexError") box.append(IndexError) except ValueError: print("ValueError: input a number beta") box.append(ValueError) for xm in box: print(xm)
CodeWithHarry please add some quizes and practice sets also in the course as you always do. So that we can practice that concepts we learned. And also make some sort of project after 30 days so that we can gain some confidence. Hope it will help.
BY CHATGPT: There are several types of errors that can occur in Python: Syntax errors: These occur when the code is not written in a proper format, and the interpreter is unable to understand it. For example, if you forget to close a parentheses or forget to indent code properly, you will get a syntax error. Name errors: These occur when you try to use a variable that has not been defined. Type errors: These occur when you try to perform an operation on a value of the wrong type. For example, if you try to add a string and a number, you will get a type error. Index errors: These occur when you try to access an element in a list or a string using an index that is out of bounds. Value errors: These occur when a built-in function receives an argument of the right type, but an inappropriate value. Attribute errors: These occur when you try to access an attribute of an object that does not exist. Import errors: These occur when you try to import a module that does not exist or cannot be found. Key errors: These occur when you try to access a dictionary with a key that does not exist. File not found errors: These occur when you try to open a file that does not exist or cannot be found. Indentation errors: These occur when the indentation of the code is not consistent, which can cause the interpreter to behave unexpectedly. Zero division errors: These occur when you try to divide a number by zero, which is not allowed in Python. Recursion errors: These occur when a function calls itself recursively, but the base case is not defined, causing the function to call itself indefinitely. Memory errors: These occur when the program tries to use more memory than the computer has available. Overflow errors: These occur when a calculation produces a result that is too large to be stored in the allocated memory. Underflow errors: These occur when a calculation produces a result that is too small to be represented accurately in the allocated memory. Assertion errors: These occur when an assert statement fails. Not implemented errors: These occur when a method or function has not been implemented yet. Runtime errors: These occur while the program is running and can be caused by a variety of factors, such as invalid input, missing resources, or other unforeseen circumstances. Security errors: These occur when the program tries to perform an action that is not allowed due to security restrictions. Timeout errors: These occur when a program takes too long to run and exceeds the allotted time limit. Unbound local errors: These occur when you try to access a local variable before it has been defined. Internal errors: These occur when the interpreter encounters an unexpected condition that it cannot handle. External errors: These occur when the program interacts with an external resource (such as a database or a network connection) and something goes wrong. It is also worth noting that Python allows you to define your own custom errors using the Exception class. This can be useful if you want to create specific error handling logic for your program.
For someone who is beginner or intermediate, => except exception as e: This line would save a lot of worries incase you are unsure which error you want to consider in the except block.
hello sir, i have tried this one: try: tup1 = (1,2,3,4,5) tup1.insert(2,9) print(tup1) # list1 = list(tup1) # list1.insert(2,9) # tup1 = tuple(list1) # print(tup1) except AttributeError : print("No changes can be made in a tuple directly, Once they are created") also this one: try: dict = {"name": "rayees", "age": 23, "roll.No.": "17e31a0333", "DOB":"23/07/1999"} # print(dict["name"]) print(dict["adhaar"]) except KeyError: print("This key do not exist in dict") Thank you so much harry sir
If you are trying to run a python program and there are chances of getting errors, then we can handle those errors using try-exception technique. We can use try keyword and can write your block of code inside the try with proper indentation and then, we have to use except keyword and then we can anything that we want to happen with the program exceution whenenver the error occurs. We can also specify the types of error with except keyword like index error, value error and can write the body that we want to excute upon error occuring.
🥳🥳🥳 nice concept , with this we can get error in the middle of code printed and check for further code's correctness after that also kind a substitute for commenting above code or doing pass 😀
Thanks Harry num=input("Enter the number to print table:") try: for i in range(1, 11): print(f'{int(num)}*{i}={i*int(num)}') except ValueError: print(f'Invalid input your input is {num} expecting number')
present sir ji today also....... Thank you sooo sooo sooo much sirji to teach us the valuable things for free....... god bless you with the best best bestest always in your life...... keep it up sirji,...... help us always like this........ huge huge huge respect for you......🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
The main thing is missing that we don't know what type of exceptions exist I try this as a exepction handle: def run(): name=input("Enter a valid string otherwise error recieved until you enter the string :") try: hi=int(name) except ValueError as e: print(e) run() run()
at 2:14 for i in range(1,11): print(f"{a} X {i}= {a*i}") why is the output like? 7,77,777,777 ? How is that generated? Please explain the logic. Thankyou.
def multiplication(): try : num = int(input("Enter the number : ")) print(f"Multiplication table for {num}:") for i in range (1, 11): result = num * i print(f"{num} x {i} = {result}") except ValueError : print("ERROR : Enter valid number !") except Exception as e : print(f"An unexpected error occured : {e}") finally : print("Execution is fully completed")
I was trying (try and except) after error it should go back to input again rerun the programme. so I wrote this a= 0 while a == int(a): try: a= int(input("Enter the number : ")) print(f"Multiplication table of {a} is : ") for i in range(1,11): print(f"{int(a)} x {i} = {int(a)*i}") break except: print("Invalid input")
# I have a problem. for i in range (1,11): try:g = int(input(f"Enter your guess.Its your chance no-{i} >>")) except:break if g == n : print(f"You guessed right number,which is {n} in chance no {i}.") break elif g < n: print("You guessed too low number.") elif g > n: print("You guessed too high number.") if i ==10: print(f"You lost! You couldn't guess the right number which was {n}.") #Mujhe es code ke except wale part me loop break karne ke sath sath kuch print v karna h kaise kara😢
Try this: n = 5 for i in range(1, 11): try: g = int(input(f"Enter your guess.Its your chance no-{i} >>")) except: print("Input is not an integer.") break if g == n: print(f"You guessed right number,which is {n} in chance no {i}.") break elif g < n: print("You guessed too low number.") elif g > n: print("You guessed too high number.") if i == 10: print(f"You lost! You couldn't guess the right number which was {n}.") Just print the statement above the break
@UC9qKbi_i7REYB5uk3xozWcg Thanks! Ye kam kar gaya mene . except: print("This is not integer.") break ase lekha tha esleya error aya tha except: print("This is not integer.") break lekin ase lekne se kam chalgaya
@@superhitragini You are using it for your benefits, but Harry bhai doesn't charge us a single penny for his courses, advertisement is the only way he can earn from. Don't use vanced or any other mod apps. It also breaches your privacy. Hope you understand.
I already reached to 58 days and using both video to create this code below: Question: # Person Class: # Create a Person class with attributes like name, age, and country. # Initialize these attributes using the __init__ method and display them using a method like display_info. class people: def __init__(self,name,age,country): self.name = name self.age =age self.country = country def info(self): print( f'Your name is {self.name} and you are {self.age} years old.You are from {self.country}' ) name = input('Enter your name: ') try: age = int(input('Enter your age: ')) except(ValueError): print('The age should be in an integer') exit() country = input('Enter your country: ') user_input = people(name,age,country) user_input.info()
Bhai explurger app kaise bana uski kitni team hai and konsi programming language use krta hai and konsa server use krta hai or development me kitna spend hua hoga pr ek video bnao please
HARRY SIR PLEASE COURSE KE END MEIN KOI TEST YA EXAM LEKE CERTIFICATION PROVIDE KARDIJIYE....DESPERATELY NEED THAT...PLEASE ALSO GIVE REGULAR PRACTICE SETS OF OLD CONCEPTS AS REVISION
hello bro🌹 can we convert a wordpress website into a python programming???? just like we change formate of a picture or video in other formate......💭💥💭💥💭💥💭💥
Hlw bro I m mechanical graduate 2020 and now 2023 i am learning python . So can I start with as a carier of software engineer . What is the right path?
This guy never ever did any paid course after teaching for this many years on TH-cam.
Huge respect for Harry bhai♥️♥️
Bhai TH-cam se earning
@@invincible4010 Bhai Paid b krr skta tha uss se zyda earning hote
Few important things to note about try and exception method:
1. We can use else clause with exception handling.
try:
result = 100 / 2
except ZeroDivisionError:
print(f"Division Error")
else:
print("Result is", result)
2. Using the finally clause in exception handling
try:
result = 10 / 0
except ZeroDivisionError:
print("Division by zero!")
finally:
print("This block of code will always execute.")
3. Raising exceptions using raise
try:
raise ValueError("This is a custom error message.")
except ValueError as e:
print("An error occurred:", str(e))
Error dikhane ka stylish way 😁😁😁😁😁😁😁😁
# My code
box=[]
while(True):
try:
num = int(input("Enter num:"))
for i in range(1,num):
print(i)
x=[2,3,4,5]
print(x[num])
break
except IndexError :
print("IndexError")
box.append(IndexError)
except ValueError:
print("ValueError: input a number beta")
box.append(ValueError)
for xm in box:
print(xm)
Hi
CodeWithHarry please add some quizes and practice sets also in the course as you always do. So that we can practice that concepts we learned. And also make some sort of project after 30 days so that we can gain some confidence. Hope it will help.
Yeah I agree with you
Totally agree with you. I have provided the same review on the 1st video as well.
I to agree
I am agree 👍👍👍
I agree
BY CHATGPT:
There are several types of errors that can occur in Python:
Syntax errors: These occur when the code is not written in a proper format, and the interpreter is unable to understand it. For example, if you forget to close a parentheses or forget to indent code properly, you will get a syntax error.
Name errors: These occur when you try to use a variable that has not been defined.
Type errors: These occur when you try to perform an operation on a value of the wrong type. For example, if you try to add a string and a number, you will get a type error.
Index errors: These occur when you try to access an element in a list or a string using an index that is out of bounds.
Value errors: These occur when a built-in function receives an argument of the right type, but an inappropriate value.
Attribute errors: These occur when you try to access an attribute of an object that does not exist.
Import errors: These occur when you try to import a module that does not exist or cannot be found.
Key errors: These occur when you try to access a dictionary with a key that does not exist.
File not found errors: These occur when you try to open a file that does not exist or cannot be found.
Indentation errors: These occur when the indentation of the code is not consistent, which can cause the interpreter to behave unexpectedly.
Zero division errors: These occur when you try to divide a number by zero, which is not allowed in Python.
Recursion errors: These occur when a function calls itself recursively, but the base case is not defined, causing the function to call itself indefinitely.
Memory errors: These occur when the program tries to use more memory than the computer has available.
Overflow errors: These occur when a calculation produces a result that is too large to be stored in the allocated memory.
Underflow errors: These occur when a calculation produces a result that is too small to be represented accurately in the allocated memory.
Assertion errors: These occur when an assert statement fails.
Not implemented errors: These occur when a method or function has not been implemented yet.
Runtime errors: These occur while the program is running and can be caused by a variety of factors, such as invalid input, missing resources, or other unforeseen circumstances.
Security errors: These occur when the program tries to perform an action that is not allowed due to security restrictions.
Timeout errors: These occur when a program takes too long to run and exceeds the allotted time limit.
Unbound local errors: These occur when you try to access a local variable before it has been defined.
Internal errors: These occur when the interpreter encounters an unexpected condition that it cannot handle.
External errors: These occur when the program interacts with an external resource (such as a database or a network connection) and something goes wrong.
It is also worth noting that Python allows you to define your own custom errors using the Exception class. This can be useful if you want to create specific error handling logic for your program.
thank you so much
Thnx lot
For someone who is beginner or intermediate, => except exception as e:
This line would save a lot of worries incase you are unsure which error you want to consider in the except block.
thanks very useful info
hello sir, i have tried this one:
try:
tup1 = (1,2,3,4,5)
tup1.insert(2,9)
print(tup1)
# list1 = list(tup1)
# list1.insert(2,9)
# tup1 = tuple(list1)
# print(tup1)
except AttributeError :
print("No changes can be made in a tuple directly, Once they are created")
also this one:
try:
dict = {"name": "rayees", "age": 23, "roll.No.": "17e31a0333", "DOB":"23/07/1999"}
# print(dict["name"])
print(dict["adhaar"])
except KeyError:
print("This key do not exist in dict")
Thank you so much harry sir
Best example💯
If you are trying to run a python program and there are chances of getting errors, then we can handle those errors using try-exception technique. We can use try keyword and can write your block of code inside the try with proper indentation and then, we have to use except keyword and then we can anything that we want to happen with the program exceution whenenver the error occurs. We can also specify the types of error with except keyword like index error, value error and can write the body that we want to excute upon error occuring.
🥳🥳🥳 nice concept , with this we can get error in the middle of code printed and check for further code's correctness after that also kind a substitute for commenting above code or doing pass 😀
Thanks Harry
num=input("Enter the number to print table:")
try:
for i in range(1, 11):
print(f'{int(num)}*{i}={i*int(num)}')
except ValueError:
print(f'Invalid input your input is {num} expecting number')
Present from Bangladesh Brother. After 6 days of busyness, I am back to this course... #Day36 Done
Thanks for giving this series Harry bhi
Please start practice series in python
#36 completed
Love code with Harry 3000❤️
please resume ML with Python video series 😭😭 really really need that
What mean of ML please tell me
@@Single_Brand.102Machine learning
#DAY36 COMPLETED
THANK YOU #CodeWithHarry
Present on Day #36th
present sir ji today also....... Thank you sooo sooo sooo much sirji to teach us the valuable things for free....... god bless you with the best best bestest always in your life...... keep it up sirji,...... help us always like this........ huge huge huge respect for you......🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
please make more detailed videos on exeption handling
u never disappoint ,, i always understand your teachings
Harry bhai... 😍😍😍
You are great🙏🏻
Thank you so much sir for creating this video!
Hi Harry,
I loved your course. Extremely helpful.
Could you please share full notes in a PDF which might help us in the revision time.
Thanks
a = input("Enter a: ")
try:
for i in range(1,11):
print(f"{int(a)} x {i} = {int(a)*i}")
except Exception as error:
print(error)
#day36 consistency maintain
20:11 2/1/2023
Present Sir on Day-36 ✋
The main thing is missing that we don't know what type of exceptions exist
I try this as a exepction handle:
def run():
name=input("Enter a valid string otherwise error recieved until you enter the string :")
try:
hi=int(name)
except ValueError as e:
print(e)
run()
run()
Brother at time1:39 why you use f outside string I didn't get it ?
Harry bahi is very good programer
Proud to learn python with you Harry bhai
after 1 month i continuing my day 35,36 video .
i enjoying this course too much.
at 2:14
for i in range(1,11):
print(f"{a} X {i}= {a*i}")
why is the output like?
7,77,777,777 ?
How is that generated? Please explain the logic. Thankyou.
def multiplication():
try :
num = int(input("Enter the number : "))
print(f"Multiplication table for {num}:")
for i in range (1, 11):
result = num * i
print(f"{num} x {i} = {result}")
except ValueError :
print("ERROR : Enter valid number !")
except Exception as e :
print(f"An unexpected error occured : {e}")
finally :
print("Execution is fully completed")
multiplication()
Hii Harry bhai
Hello Harry Bhai, Plz make a Video on "'Subprocess Module" and other stuff related to that e.g PIPE, STDIN, STDOUT etc. thank You!
Day #36 completed!
Present Sir, #Day_8 !!!
Pranam bhrata 🙏 apka bahutt baht dhanyawad🙏😍😇❤️
sir mai pahle error ko isdigit() se solve karta tha
par ye to nwe scheme pata chali
thanks sir itna kuch sikhnaa ke liye
I was trying (try and except) after error it should go back to input again rerun the programme. so I wrote this
a= 0
while a == int(a):
try:
a= int(input("Enter the number : "))
print(f"Multiplication table of {a} is : ")
for i in range(1,11):
print(f"{int(a)} x {i} = {int(a)*i}")
break
except:
print("Invalid input")
Day #36 in 100DaysOfCode. Enjoying this advanced concepts
Present sir 🤚
# I have a problem.
for i in range (1,11):
try:g = int(input(f"Enter your guess.Its your chance no-{i}
>>"))
except:break
if g == n :
print(f"You guessed right number,which is {n} in chance no {i}.")
break
elif g < n:
print("You guessed too low number.")
elif g > n:
print("You guessed too high number.")
if i ==10:
print(f"You lost!
You couldn't guess the right number which was {n}.")
#Mujhe es code ke except wale part me loop break karne ke sath sath kuch print v karna h kaise kara😢
Try this:
n = 5
for i in range(1, 11):
try:
g = int(input(f"Enter your guess.Its your chance no-{i}
>>"))
except:
print("Input is not an integer.")
break
if g == n:
print(f"You guessed right number,which is {n} in chance no {i}.")
break
elif g < n:
print("You guessed too low number.")
elif g > n:
print("You guessed too high number.")
if i == 10:
print(f"You lost!
You couldn't guess the right number which was {n}.")
Just print the statement above the break
Break ke upar wo line write karo
@@sudhansubalasahoo Try keya but kam nahi keya
@@sakshamraj7872 I tried and it works
@UC9qKbi_i7REYB5uk3xozWcg Thanks! Ye kam kar gaya mene .
except: print("This is not integer.")
break
ase lekha tha esleya error aya tha
except:
print("This is not integer.")
break
lekin ase lekne se kam chalgaya
thank you brother
"Tired Of CodingNinja Ads On Harry Bhai Videos" Raised a Hand ✋️
I am ad vanced
Me 2
@@superhitragini once upon a Time, I'm Also User Of Vanced🍭
@@superhitragini You are using it for your benefits, but Harry bhai doesn't charge us a single penny for his courses, advertisement is the only way he can earn from. Don't use vanced or any other mod apps. It also breaches your privacy. Hope you understand.
@@shubhajitchakraborty No? 🤣
I already reached to 58 days and using both video to create this code below:
Question:
# Person Class:
# Create a Person class with attributes like name, age, and country.
# Initialize these attributes using the __init__ method and display them using a method like display_info.
class people:
def __init__(self,name,age,country):
self.name = name
self.age =age
self.country = country
def info(self):
print( f'Your name is {self.name} and you are {self.age} years old.You are from {self.country}' )
name = input('Enter your name: ')
try:
age = int(input('Enter your age: '))
except(ValueError):
print('The age should be in an integer')
exit()
country = input('Enter your country: ')
user_input = people(name,age,country)
user_input.info()
this man is amazing, I love it
Day 36 of 100 of python challenge completed. #100DaysofCode #100dayspythonchallenge
Thank you so much!
Hi Harry, Have u ever tried for bug bounty hunting in ur life out of curiosity? What was your experience? Did u find it too hard?
Bhai explurger app kaise bana uski kitni team hai and konsi programming language use krta hai and konsa server use krta hai or development me kitna spend hua hoga pr ek video bnao please
35 course are very good
#day36 love you harry bro you are really genius bro💖💖💝
Bhai aapko all MacBook ko compare karke kiske liye konsa best h video bana kar suggest krna cahiye 🤔🤔🤔
DAY36-PRESENT SIR!
Greak work !!
Thanks a lot !!
kamal harry bhai
HARRY SIR PLEASE COURSE KE END MEIN KOI TEST YA EXAM LEKE CERTIFICATION PROVIDE KARDIJIYE....DESPERATELY NEED THAT...PLEASE ALSO GIVE REGULAR PRACTICE SETS OF OLD CONCEPTS AS REVISION
You vibe amazing man!!
Bhai meri marzi, mera keyboard... 2:47 😂🤣
Harry bhai great teacthing style.
Harry bhai kal aur aj ka video ek no tha bhai 🙏🙏❤️
Present bhai
Wahhh Thumbnail OP HAI
Syntax
try:
except:
or
except name:
We can use many except as required
LOVE YOU HARRY BHAI❤
Thanks for try and except codes for python
Harry sir, may you make a new course on spring boot api using java
nice video
it is same like java try and catch block
thank you
Present Harry Sir!
sir i am waiting for this topic . I do mistake . i understood this concept 🖐🖐
Thanks, Harry Bhai
How does Python know which "Except" to get into? Are the types of errors and their "except" already predefined?
Day 36 completed.
Sir can we have a detailed course on dbms please
Present Sir 🤚
thanks man
I wonder why python is so damn simple as compared to Java yo
hello bro🌹
can we convert a wordpress website into a python programming????
just like we change formate of a picture or video in other formate......💭💥💭💥💭💥💭💥
Nice
#Completed DAY#36 😍
How was your experience then? And how much coding did you learned in phyton...... Can you just share ? And he said 100 days but there is only 36 days?
@@onlysahil Vai 100 days hi hoga....aj 36 day chal raha hain...ab tak bohut accha future main to dhamal hoga...
Day 36 Done
Best sir
Harry vai first comment big fan sir
Thanks sir.
🤞
Hello Harry bhai
I'm in class 11 & I want To become Python Software Developer so should I need to do BCA or BTech
PLEASE Answer
Only code with harry
Present Sir 🔥
Day36.. Present Sir
Type of error next plz
Brother make a video on how to update react js and node js code on already hosted sites on cpanel hosting.
bro pls pls make a video on how to make raycast engine in python
Day 36 🔥
Hlw bro I m mechanical graduate 2020 and now 2023 i am learning python . So can I start with as a carier of software engineer .
What is the right path?
Yes bro
#day36 completed
very good explanation👍👍👍👍
Game development full course please
Day 36 done sir
thankyou
Day 36 done