10. Implementing real-time/technical applications using Exception handling. (divide by zero error, voter’s age validity, student mark range validation) Program a=int(input("Entre a=")) b=int(input("Entre b=")) try: c = ((a+b) / (a-b)) #Raising Error if a==b: raise ZeroDivisionError #Handling of error except ZeroDivisionError: print ("a/b result in 0") else: print (c) Output Enter a=4 Enter b=4 a/b result in 0 Voter’s age validity a=int(input("Enter your age")) try: c = a #Raising Error if c<18: raise ValueError #Handling of error except ValueError: print ("not eligible for voting - enter above 18") else: print (c) Student ...
11. Exploring Pygame tool. Pygame Pygame is a cross-platform set of Python modules which is used to create video games. It consists of computer graphics and sound libraries designed to be used with the Python programming language. Pygame was officially written by Pete Shinners to replace PySDL. Pygame is suitable to create client-side applications that can be potentially wrapped in a standalone executable. Pygame Installation Install pygame in Windows Before installing Pygame, Python should be installed in the system, and it is good to have 3.6.1 or above version because it is much friendlier to beginners, and additionally runs faster. There are mainly two ways to install Pygame, which are given below: 1. Installing through pip: The good way to install Pygame is with the pip tool (which is what python uses to install packages). The command is the following: 1. py -m pip install...
Comments
Post a Comment