author | Puneeth Chaganti <punchagan@fossee.in> |
Mon, 11 Oct 2010 00:59:36 +0530 | |
changeset 276 | 89437325b326 |
parent 236 | 33828497b5da |
child 329 | 5c8e88276e1f |
permissions | -rw-r--r-- |
236
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
1 |
.. Objectives |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
2 |
.. ---------- |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
3 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
4 |
.. A - Students and teachers from Science and engineering backgrounds |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
5 |
B - |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
6 |
C - |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
7 |
D - |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
8 |
|
276 | 9 |
.. #. How to print some value |
10 |
.. #. How to print using modifiers |
|
11 |
.. #. How to take input from user |
|
12 |
.. #. How to display a prompt to the user before taking the input |
|
13 |
||
14 |
||
236
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
15 |
.. Prerequisites |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
16 |
.. ------------- |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
17 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
18 |
.. 1. Loops |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
19 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
20 |
.. Author : Nishanth Amuluru |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
21 |
Internal Reviewer : |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
22 |
External Reviewer : |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
23 |
Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
24 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
25 |
Script |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
26 |
------ |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
27 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
28 |
Hello friends and welcome to the tutorial on Input/Output |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
29 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
30 |
{{{ Show the slide containing title }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
31 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
32 |
{{{ Show the slide containing the outline slide }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
33 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
34 |
Input and Output are used in almost every program we use. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
35 |
In this tutorial, we shall learn |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
36 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
37 |
* Outputting data |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
38 |
* Taking input from the user |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
39 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
40 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
41 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
42 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
43 |
a = "This is a string" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
44 |
a |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
45 |
print a |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
46 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
47 |
print a prints the value of a which is obvious. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
48 |
As you can see, even when you type just a, the value of a is shown. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
49 |
But there is a difference. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
50 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
51 |
Typing a shows the value of a while print a prints the string. This difference |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
52 |
becomes more evident when we use strings with newlines in them. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
53 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
54 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
55 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
56 |
b = "A line \n New line" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
57 |
b |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
58 |
print b |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
59 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
60 |
As you can see, just typing b shows that b contains a newline character. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
61 |
While typing print b prints the string and hence the newline. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
62 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
63 |
Moreover when we type just a, the value a is shown only in interactive mode and |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
64 |
does not have any effect on the program while running it as a script. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
65 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
66 |
We shall look at different ways of outputting the data. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
67 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
68 |
print statement also accepts the syntax of C's printf statement. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
69 |
Various arguments can be passed to print using modifiers. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
70 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
71 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
72 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
73 |
x = 1.5 |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
74 |
y = 2 |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
75 |
z = "zed" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
76 |
print "x is %2.1f y is %d z is %s"%(x,y) |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
77 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
78 |
As you can see, the values of x and y are substituted in place of %2.1f and %d |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
79 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
80 |
{{{ Pause here and try out the following exercises }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
81 |
|
276 | 82 |
%% 1 %% What happens when you do ``print "x is %d y is %f" %(x, y)`` |
236
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
83 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
84 |
{{{ continue from paused state }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
85 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
86 |
We see that the int value of x and float value of y are printed corresponding |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
87 |
to the modifiers used in the print statement. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
88 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
89 |
We can also see that print statement prints a new line character at the end of |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
90 |
line, everytime it is called. This can be suppressed by using a "," at the end |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
91 |
print statement. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
92 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
93 |
Let us see this by typing out following code on an editor as print_example.py |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
94 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
95 |
{{{ open an editor }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
96 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
97 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
98 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
99 |
print "Hello" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
100 |
print "World" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
101 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
102 |
print "Hello", |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
103 |
print "World" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
104 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
105 |
Now we run the script using %run /home/fossee/print_example.py |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
106 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
107 |
As we can see, the print statement when used with comma in the end, prints a |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
108 |
space instead of a new line. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
109 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
110 |
Now we shall look at taking input from the user. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
111 |
We will use the ~~raw_input~~ for this. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
112 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
113 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
114 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
115 |
ip = raw_input() |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
116 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
117 |
The cursor is blinking indicating that it is waiting for input |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
118 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
119 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
120 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
121 |
an input |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
122 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
123 |
and hit enter. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
124 |
Now let us see what is the value of ip by typing. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
125 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
126 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
127 |
ip |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
128 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
129 |
We can see that it contains the string "an input" |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
130 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
131 |
{{{ Pause here and try out the following exercises }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
132 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
133 |
%% 2 %% enter the number 5.6 as input and store it in a variable called c. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
134 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
135 |
{{{ continue from paused state }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
136 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
137 |
We have to use the raw_input command with variable c. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
138 |
type |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
139 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
140 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
141 |
c = raw_input() |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
142 |
5.6 |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
143 |
c |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
144 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
145 |
Now let us see the type of c. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
146 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
147 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
148 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
149 |
type(c) |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
150 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
151 |
We see that c is a string. This implies that anything you enter as input, will |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
152 |
be taken as a string no matter what you enter. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
153 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
154 |
{{{ Pause here and try out the following exercises }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
155 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
156 |
%% 3 %% What happens when you do not enter anything and hit enter |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
157 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
158 |
{{{ continue from paused state }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
159 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
160 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
161 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
162 |
d = raw_input() |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
163 |
<RET> |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
164 |
d |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
165 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
166 |
We see that when nothing is entered, an empty string is considered as input. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
167 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
168 |
raw_input also can display a prompt to assist the user. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
169 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
170 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
171 |
name = raw_input("Please enter your name: ") |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
172 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
173 |
prints the string given as argument and then waits for the user input. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
174 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
175 |
{{{ Pause here and try out the following exercises }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
176 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
177 |
%% 4 %% How do you display a prompt and let the user enter input in a new line |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
178 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
179 |
{{{ continue from paused state }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
180 |
|
276 | 181 |
.. #[Puneeth: We didn't talk of new-line character till now, did we?] |
182 |
.. #[Puneeth: non-programmers might not know?] |
|
183 |
||
236
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
184 |
The trick is to include a newline character at the end of the prompt string. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
185 |
:: |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
186 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
187 |
ip = raw_input("Please enter a number in the next line\n> ") |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
188 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
189 |
prints the newline character and hence the user enters input in the new line |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
190 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
191 |
{{{ Show summary slide }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
192 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
193 |
This brings us to the end of the tutorial. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
194 |
we have learnt |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
195 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
196 |
* How to print some value |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
197 |
* How to print using modifiers |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
198 |
* How to take input from user |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
199 |
* How to display a prompt to the user before taking the input |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
200 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
201 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
202 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
203 |
#[Nishanth]: Will add this line after all of us fix on one. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
204 |
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
205 |
|
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
206 |
Hope you have enjoyed and found it useful. |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
207 |
Thankyou |
33828497b5da
Converted input_output to new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
208 |