Python Beginner Tutorial 6 - Exceptions and Loops

preview_player
Показать описание
This tutorial covers exception handling in Python with try/except and introduces the concept of looping with the while loop. After watching this video you should feel conformable using the try except block to handle errors and using while loops.

Рекомендации по теме
Комментарии
Автор

OUTSTANDING! YOUR VERY GENEROUS WITH YOUR KNOWLEDGE AND SKILLS. THE WORLD NEEDS MORE POEPLE LIKE YOU!!!

kodimonster
Автор

Thx for making my life easier. I've been wondering about how to restart a program

harrisongazeley
Автор

You are a good teacher, judging by the fact that I managed to get my calculator looping as long as you said Y or y to continuing before I even watched this video.

DutchDread
Автор

I'm a little late to the party but wanted to say that these are great tutorials for first timers and the challenges are very useful also. Lessons are much appreciated.

dez
Автор

keep it up your the only person that actually taught me properly and your not boring

peesicle
Автор

These vids are great! I used python a few years ago for school but haven't touched it since and now im really rusty and this is helping me get back into things!

redfare
Автор

Awesome Tutorials! Thanks very much for all your effort!

richmilliarsen
Автор

Amazing! i getting more hook up with python more everyday i even bought a the book Python crash course. Great book i recommended for everyone who want to get started in python. Love the video my man love how you explain every detail great work and thank you for making these video.

walterroman
Автор

@kjdElectronics For the task of this episode:
There is no need to to a while around all the code. Do a while just around the main() and include an if works as well ;)

Great videos started watching them today and cant stop =)

johnp
Автор

6:47 I thought you said the Pepe guidelines.

WildE_
Автор

Thanks, it help me alot, my try exept wasn't working well in a while loop, making a second one worked !

charlestaylor
Автор

Love these videos! Very helpful for beginners

nicholasegan
Автор

I had complied a code which also does the same thing like this but runs in a different way

while 1==1 :

num1 = int(input("What is number 1 ? "))
num2 = int(input("What is number 2 ? "))
operation = input("What do you want to do ( add, multiply, divide, subtract)")
if (operation == 'add'):
print(add(num1, num2))
elif (operation == 'subtract'):
print(sub(num1, num2))
elif (operation == 'divide'):
print(div(num1, num2))
elif (operation == 'multiply'):
print(mul(num1, num2))
else:
print("Please choose from the options add, multiply, divide, subtract")

Choice = input("If you want to calculate again type (redo) and if you want to quit type (quit)")
if (Choice == 'redo'):

num1 = int(input("What is number 1 ? "))
num2 = int(input("What is number 2 ? "))
operation = input("What do you want to do ( add, multiply, divide, subtract)")
if (operation == 'add'):
print(add(num1, num2))
elif (operation == 'subtract'):
print(sub(num1, num2))
elif (operation == 'divide'):
print(div(num1, num2))
elif (operation == 'multiply'):
print(mul(num1, num2))
else:
print("Please choose from the options add, multiply, divide, subtract")

elif (Choice == 'quit'):
print("Thanks a lot !! ")

exit()

else:
print("Please choose from 'quit' or 'redo'")

shubhayusarkar
Автор

I personally think the challenges are fun. And since you use the output in the new program, they are helpful as part of the learning process.

andrewwolan
Автор

Or you could just recall the main() function without using a loop 7:50
Like it's the first thing you run on the main() function

charleskhoury
Автор

brilliant explanation man! the best out there by far for python. There's just one thing i don't understand and that is the 'validinput' bit, why is assigned to false and why do you say 'while not' validinput. Once again thanks for putting out these videos they've helped me

eesaakhan
Автор

Hello i put the command

print(“hello”) and print(“world”)
Result- hello

And when i put

print(“hello”) or print(“world”)
Result- hello
World
Why this?

sehrannoor
Автор

For some reason, I wasn't able to loop with your method, but I got it working when I did this:

def main():
runAgain = False
while not (runAgain):
try:
num1 = int(input("Enter num1: "))
num2 = int(input("Enter num2: "))
operation = int(input("What do you want to do? 1. add, 2. div, 3. sub, 4. mul: "))

if operation == 1:
print(add(num1, num2))
elif operation == 2:
print(div(num1, num2))
elif operation == 3:
print(sub(num1, num2))
elif operation == 4:
print(mul(num1, num2))
else:
print("try again")
while runAgain:
return
except:
print("try again")
while runAgain:
return



main()

Jackxagon
Автор

I'm getting my exception statement to print, but it's going onto the next part of the program and not looping back to retry a correct entry. I don't know what I am doing wrong.

georgemckay
Автор

great lessons! But the background should be white because it is much more relaxing for our eyes

teosidi