Page 171 - Ai_V3.0_c11_flipbook
P. 171

Run a Program
                 Follow these steps to run a Python program:
                 Step 1:   Click on the Run menu in the Menu bar. Alternately, press F5 to run the program.
                 Step 2:   Select on the Run Module option.












                 The program will execute and the output will be shown in the Shell window.
















                         Input and Output

                 Python provides two commonly used functions input() and print() for input and output.
                  • •    The input() Function: The input() function takes the user’s input while a program executes. When called, it waits
                     for the user to type something on the keyboard and press the Enter key. The function then returns the user input as
                     a string. The syntax of the input() function is as follows:

                     input([<prompt>])
                     Where, prompt is the string or message we wish to display on the screen.
                     Example:

                     name = input("Enter your name: ")
                  • •    The print() Function: The print() function prints or sends the output to the standard output device, which
                     is usually a monitor. This function auto converts the items to strings, i.e., if you try printing a numeric value, the
                     print() function will automatically convert it into an equivalent string and print it. The print() function also
                     introduces spaces between items automatically with the help of the comma operator.
                 •   The syntax of the print() function is as follows:
                     print (<expression 1> , <expression 2>...)
                     Example:
                     print ("Python is easy")

                  Program 1: To demonstrate the use of the input( ) and print( ) functions

                     name =input("Enter your name: ")
                     age =input("Enter your age: ")
                     print(name,"your age is", age)
                      Output:

                     Enter your name: Yash
                     Enter your age: 25
                     Yash your age is 25
                                                                                         Python Programming     169
   166   167   168   169   170   171   172   173   174   175   176