# name = input('What is your name?\n') # print('Hi, %s.' % name) # from words import * # website = input('Website URL\n') # main(website) # fetch_words() # from db_train import db_test # db_test() # from words2 import * # website = input('Website URL to try\n') # main(website) #from lists_with_strings import * # let user input their own values #userInputs = input('Enter some values separated by a space:\n') #main(userInputs) from exceptional import convert convert("one three three seven".split())
from exceptional import convert convert("33")
from exceptional import convert print(convert('one three three seven'.split())) # print(convert('around two grillion'.split())) # Error KeyError: 'around' # After add except KeyError. print(convert('three four'.split())) print(convert('eleven'.split())) # print(convert(512)) # Error TypeError: 'int' object is not iterable # After add TypeError print(convert(512)) # ########################### # Programer errors: # # - IndentationError # - SyntaxError # - NameError # # These should almost never be caught ############################# # Accessing Exception Objects # # exceptional_ver_after3
from exceptional import convert print(convert('33')) print(convert('porcupine'))
# print (math.factorial(5)) # # #print (math.factorial(100)) # # # from urllib.request import urlopen # # with urlopen('http://sixty-north.com/c/t.txt') as story: # story_words = [] # for line in story: # line_words = line.decode('utf-8').split() # for word in line_words: # story_words.append(word) # # for word in story_words: # print(word) #import words # main("http://sixty-north.com/c/t.txt") # help(fetch_words) #help(words) from exceptional import convert from exceptional import string_log convert("33") convert("hedgehog") convert([4, 5, 6]) string_log("ouch")
try: number = '' tab = [] for token in s: number += tab[token] x = int(number) print(f'Conversion succeeded! x = {x}') except (KeyError, TypeError): print(f'Conversion failed!') x = -1 return x from exceptional import convert convert("nine") # In[22]: import sys def sqrt(x): if x < 0: raise ValueError( # ici on leve l'exception ave le mot clé raise "Impossible de calculer la racine carée" f" d\'un nombre négatif {x}") guess = x i = 0 while guess * guess != x and i < 20:
def test_Numbers_convert(self): self.assertEqual(convert('5'), 5, "The number did not convert")