Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 111 - 2611_SmartGPT Pro V(5.0) C-6
P. 111

    SCRIPT MODE (EDITOR’S WINDOW)

                     Python Shell executes commands immediately and doesn’t save
                     them for later use. For multi-line code and to save your work for             To close IDLE window:
                     future use, you should use Python script mode. This allows you to          Short key
                     write larger programs and run the same code multiple times. Save                  Ctrl +     D
                     your code in a file, for example, ‘filename.py’ and run it to see all
                     the output after execution. To open Python Editor’s Window: click

                     on the File menu    click on the New File option.

                     The output is displayed in the Python Shell window.

                               INPUT AND OUTPUT

                     Python  provides  two  commonly  used  functions  input()  and  print()  for input  and  output
                     respectively.

                     THE input() FUNCTION

                     We use the  input()  function  to  take  the user’s input  while a program is being  executed.
                     (This function also evaluates the expression whether the user has entered a string, number or list
                     right after receiving input.) The general syntax of the input() function is as follows:

                     Variable_name = input(<message to be displayed>)

                     Example:

                     >>> name = input("Enter your name: ")

                          Enter your name: Trackpad
                     By default, Python considers the input as string even if you entered a number as input. You cannot
                     perform calculations on string. To perform calculations, you need to convert the string into integer

                     or floating-point value.

                                                                                                 Introduction to Python  109

| 106 107 108 109 110 111 112 113 114 115 116 |