input_output/script.rst
changeset 416 06ac45f4de88
parent 329 5c8e88276e1f
child 418 8a42b4203f6d
equal deleted inserted replaced
415:8afa31ae6129 416:06ac45f4de88
    17    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    17    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    18 
    18 
    19 Script
    19 Script
    20 ------
    20 ------
    21 
    21 
    22 Hello friends and welcome to the tutorial on Input/Output
    22 Hello friends and welcome to this tutorial on Input/Output
    23 
    23 
    24 {{{ Show the slide containing title }}}
    24 {{{ Show the slide containing title }}}
    25 
    25 
    26 {{{ Show the slide containing the outline slide }}}
    26 {{{ Show the slide containing the outline slide }}}
    27 
    27 
    36  
    36  
    37     a = "This is a string"
    37     a = "This is a string"
    38     a
    38     a
    39     print a
    39     print a
    40      
    40      
    41 print a prints the value of a which is obvious.
    41 print a, prints the value of a.
    42 As you can see, even when you type just a, the value of a is shown.
    42 As you can see, even when you type just a, the value of a is shown.
    43 But there is a difference.
    43 But there is a difference.
       
    44 
       
    45 .. #[Amit: The next sentence does seem to be clear enough]
    44 
    46 
    45 Typing a shows the value of a while print a prints the string. This difference
    47 Typing a shows the value of a while print a prints the string. This difference
    46 becomes more evident when we use strings with newlines in them.
    48 becomes more evident when we use strings with newlines in them.
    47 type
    49 type
    48 ::
    50 ::
    57 Moreover when we type just a, the value a is shown only in interactive mode and
    59 Moreover when we type just a, the value a is shown only in interactive mode and
    58 does not have any effect on the program while running it as a script.
    60 does not have any effect on the program while running it as a script.
    59 
    61 
    60 We shall look at different ways of outputting the data.
    62 We shall look at different ways of outputting the data.
    61 
    63 
    62 print statement also accepts the syntax of C's printf statement.
    64 .. #[Amit: C's printf syntax ?? i think its better to elaborate the
       
    65    idea]
       
    66 
       
    67 print statement  in python supports string formatting.
    63 Various arguments can be passed to print using modifiers.
    68 Various arguments can be passed to print using modifiers.
    64 type
    69 type
    65 ::
    70 ::
    66 
    71 
    67     x = 1.5
    72     x = 1.5
   166 
   171 
   167 prints the string given as argument and then waits for the user input.
   172 prints the string given as argument and then waits for the user input.
   168 
   173 
   169 {{{ Pause here and try out the following exercises }}}
   174 {{{ Pause here and try out the following exercises }}}
   170 
   175 
   171 %% 4 %% How do you display a prompt and let the user enter input in a new line
   176 %% 4 %% How do you display a prompt and let the user enter input in next line
   172 
   177 
   173 {{{ continue from paused state }}}
   178 {{{ continue from paused state }}}
   174 
   179 
   175 .. #[Puneeth: We didn't talk of new-line character till now, did we?]
   180 .. #[Puneeth: We didn't talk of new-line character till now, did we?]
   176 .. #[Puneeth: non-programmers might not know?]
   181 .. #[Puneeth: non-programmers might not know?]
   177 
   182 
       
   183 .. #[Amit: Well there is a discussion earlier about new lines, I think its good
       
   184 .. as a slight trick question. But may be next line is a more easier lexicon]
       
   185 
   178 The trick is to include a newline character at the end of the prompt string.
   186 The trick is to include a newline character at the end of the prompt string.
   179 ::
   187 ::
   180 
   188 
   181     ip = raw_input("Please enter a number in the next line\n> ")
   189     ip = raw_input("Please enter a number in the next line\n> ")
   182 
   190 
   183 prints the newline character and hence the user enters input in the new line
   191 prints the newline character and hence the user enters input in the next line
   184 
   192 
   185 {{{ Show summary slide }}}
   193 {{{ Show summary slide }}}
   186 
   194 
   187 This brings us to the end of the tutorial.
   195 This brings us to the end of the tutorial.
   188 we have learnt
   196 In this totorial we have learnt
   189 
   197 
   190  * How to print some value
   198  * How to print some value
   191  * How to print using modifiers
   199  * How to print using modifiers
   192  * How to take input from user
   200  * How to take input from user
   193  * How to display a prompt to the user before taking the input
   201  * How to display a prompt to the user before taking the input
   194 
   202 
   195 {{{ Show the "sponsored by FOSSEE" slide }}}
   203 {{{ Show the "sponsored by FOSSEE" slide }}}
   196 
   204 
   197 #[Nishanth]: Will add this line after all of us fix on one.
   205 
   198 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   206 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   199 
   207 
   200 Hope you have enjoyed and found it useful.
   208 Hope you have enjoyed and found it useful.
   201 Thankyou
   209 Thank You.
   202  
   210