0% found this document useful (0 votes)
14 views

Python 6,7,8

Uploaded by

prajwal pawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views

Python 6,7,8

Uploaded by

prajwal pawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
SS : Practical No: 6 aE x > Programs yor poxe'ng of Jaro ,volidadions like | email, val de > + Password Validation import re Pod = ‘xdebF gg! req "4 (1 =. ¥ [a-2]) (2 =. #0A-2)) C2 if teed J)fa-taz\dag leu *? Giz, t29F | 4 Compiling wegex match ve = 7e. compile (eq) + Beacching regex Tee =e. BearchCmate =, ¥\d) (2=.*10$1%* h_ve, pswd) He Volidlat'ng Conditions if Yee: print (“Valid password ") else: print (“Tnvalid password ") 4# Dviver Code if_ — name_— = main 0) Output: Thvabid Password. _— main --'4: "POR validahon — He Import: library import ve rH Url link , S= "https + // www. navishkh.ovg/ “Bio ding the protocol Objt =ve-Findau (' Cw): I, 8) Print (obj x) > AE Bind » [0 J 25 ve. Findall (°% [www (C{w\=\.74)',8) , | Print (obj 2) Outpub:- U https] ['navishkh . ovq'] eo ee 80 Oe 4 Email Validation Import ve 4& Make a reqular expression , [efor Validlecting an Email a-2) {2,74 \b' Ae Define a funchon for pe For Validahion an Email def check (emai) : +t pass the Tegular expression +t and the String Into fullmeatchO) method if (ee Fulmakch (regex , email )): print ("Valid Email”) rg hostname which may contain dash or dots regex = ¥'\ bIA-za-20-9._% + J+@ [A-za-z0-9,-J 4\. [Az | aI e eo *» s-e- 8 8 8-678: Ss cee print (“Invalid Email”) # Drivee code \ #_ name_~ == ‘__ main Enter the email email = “[email protected]" Calling eran function check Cemai!) email = "mg. ownsite @our-earth.org” check Cemajl) email =" nai, com” check Cemail ) Outpub:- Valid Email Valid Email Tovab'd Email ——--—- oeceoecoceoeoeeeeeeee oee535o5+cgeoe@8# wv we @ Practical No.8 P-Programs Covering all the aspects of Exception handling , 3 See defined exception, Multithreading should be covered. © Exception handling :- Xample 1: amount = 10000 iF Camount > 2999) PYINE ("You are eligible t0 purchase Osa self paced’) Ouspur: if (amount » 2999) “A Syntax Error: invalid Syntax Example 2: Maxks= 40000 a = maxks | 0 print Ca) Output i- ZexoDivision Error: division by Zexo Example 3: x a=[1,2,3) try: print ("Second elements vod "4. (a(al)) print ( Fourth element=%d" % (a [3})) except : pTID ("An exxor occured") Output :- second elements 2 An exror occured © OR Example us det bye (a,b): try: c= (l(atb) | Ca-b)) Except zexoDivisionError: Print (“al bresut in oF else. printlo Aby® (2.0 ,3:0) Rbye (2-0 ,3-0) Output: -s-o albvrepult in 0 Example Sie try + vaiee Mame brror (“Hi there") except (Wametrror: Print C" an exception") raise © Oude = raise MameError (“ Wi there") Wamefrror: Hi there. B.2 multithreading im pore threading det print cube (num): Print (* cube 45" format (num * num * num) det Print. square (num): a Square .3F ” format (num * num)) fe —Name_-=="__ main. _” 4 Crecching thread +4 = threading -Threacl (targets print. square , args =10,)) t2 = threading, Thread (target = print_cube, args-1o,)) +4. Storch O tz. start 0 t1- joind +2. join0 print ("Done |") Outpur:- Square = 100 Cube = 1000 Donel ve @ @ w

You might also like