Page 448 - CITS - Computer Software Application -TT
P. 448

COMPUTER SOFTWARE APPLICATION - CITS




           This Python module does not accept complex data types. The more complicated equivalent is the math module.
           We can, for example, calculate all trigonometric ratios for any given angle using the built-in functions in the math
           module. We must provide angles in radians to these trigonometric functions (sin, cos, tan, etc.). However, we are
           accustomed to measuring angles in terms of degrees. The math module provides two methods to convert angles
           from radians to degrees and vice versa.
           Program code 2:

           Here we give an example of a math module in Python for calculating the factorial of a number. The code is given
           below -
           1  import math

           2  n=int(input())
           3  print(math.factorial(n))
           Output:
           Now we compile the above code in Python, and after successful compilation, we run it. Then the output is given
           below -
           5
           120

           Python User Input
           User Input
           Python allows for user input.
           That means we are able to ask the user for input.
           The method is a bit different in Python 3.6 than Python 2.7.
           Python 3.6 uses the input() method.

           Python 2.7 uses the raw_input() method.
           The following example asks for the username, and when you entered the username, it gets printed on the screen:
           Python 3.6
           username = input(“Enter username:”)

           print(“Username is: “ + username)
           OUTPUT
           ENTER USERNAME:


            Modules, Input and Output


           Python input
           How to Take Input from User in Python
           Sometimes a developer might want to take user input at some point in the program. To do this Python provides
           an input() function.
           Syntax:
           input(‘prompt’)
           where prompt is an optional string that is displayed on the string at the time of taking input.
           Example 1: Python get user input with a message

           •  Python3



                                                           435

 CITS : IT&ITES - Computer Software Application - Lesson 120 - 137  CITS : IT&ITES - Computer Software Application - Lesson 120 - 137
   443   444   445   446   447   448   449   450   451   452   453