Difference between revisions of "Python/C3/I-O/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Visual Cue !Narration |- | 0:00 | Hello friends and welcome to this tutorial on 'Input/Output'. |- | 0:05 | At the end of this tutorial,you will be able to, # Prin…')
 
Line 27: Line 27:
 
|-
 
|-
 
| 0:45
 
| 0:45
| obviously, <tt>print a</tt>, prints the value of <tt>a</tt>.
+
| obviously, print a , prints the value of a .
  
 
|-
 
|-
Line 39: Line 39:
 
|-
 
|-
 
| 1:01
 
| 1:01
| Typing just <tt>a</tt> displays the content of <tt>a</tt> whereas the statement <tt>print a</tt> prints the string itself.  
+
| Typing just   a displays the content of a whereas the statement print a prints the string itself.  
  
 
|-
 
|-
Line 53: Line 53:
 
|-
 
|-
 
| 1:35  
 
| 1:35  
| As you can see, just typing <tt>b</tt> shows that b contains a newline character but While typing <tt>print b</tt>,it prints the string and hence the newline.
+
| As you can see, just typing b shows that b contains a newline character but While typing print b,it prints the string and hence the newline.
  
 
|-
 
|-
 
| 1:46
 
| 1:46
| Moreover when we type just <tt>a</tt>, the value a is shown only in interactive mode and does not have any effect on the program while running it as a script.
+
| Moreover when we type just a , the value a is shown only in interactive mode and does not have any effect on the program while running it as a script.
  
 
|-
 
|-
Line 81: Line 81:
 
|-
 
|-
 
| 2:51
 
| 2:51
| As you can see, the values of x, y and z are substituted in place of the modifiers <tt>modula 2.1f</tt>, <tt>modula d</tt> and <tt>modula s</tt> respectively.
+
| As you can see, the values of x, y and z are substituted in place of the modifiers modula 2.1f, modula d and modula s respectively.
  
 
|-
 
|-
Line 89: Line 89:
 
|-
 
|-
 
| 3:08
 
| 3:08
| What happens when you do <tt>print  within double quotes x is modula d comma  y is modula f modula within brackets x comma  y</tt>
+
| What happens when you do print  within double quotes x is modula d comma  y is modula f modula within brackets x comma  y
 
+
 
|-
 
|-
 
| 3:19
 
| 3:19
Line 101: Line 100:
 
|-
 
|-
 
| 3:50
 
| 3:50
| We see that the <tt>int</tt> value of x and <tt>float</tt> value of y are printed corresponding to the modifiers used in the print statement.
+
| We see that the int value of x and float   value of y are printed corresponding to the modifiers used in the print statement.
  
 
|-
 
|-
 
| 3:58
 
| 3:58
| We have seen that <tt>print</tt> statement prints a new line character everytime it is called.  
+
| We have seen that print statement prints a new line character every time it is called.  
  
 
|-
 
|-
 
| 4:04
 
| 4:04
| This can be suppressed by using a " comma " at the end of the <tt>print</tt> statement.
+
| This can be suppressed by using a " comma " at the end of the print statement.
  
 
|-
 
|-
Line 287: Line 286:
 
|-
 
|-
 
| 9:47
 
| 9:47
| 3. Take input from user by using <tt>raw underscore input()</tt>.
+
| 3. Take input from user by using raw underscore input().
  
 
|-
 
|-
 
| 9:55
 
| 9:55
| 4. Display a prompt to the user before taking the input by passing a string as an argument to <tt>raw underscore input</tt>.
+
| 4. Display a prompt to the user before taking the input by passing a string as an argument to raw underscore input.
  
 
|-
 
|-
Line 299: Line 298:
 
|-
 
|-
 
| 10:08
 
| 10:08
| 1. <tt>a = raw underscore input()</tt> and user enters <tt>2.5</tt>.  
+
| 1. a = raw underscore input() and user enters 2.5 .  
  
 
|-
 
|-
Line 311: Line 310:
 
|-
 
|-
 
| 10:20
 
| 10:20
| 2. <tt>'''a = 2</tt> and <tt>b = 4.5</tt>.  
+
| 2. '''a = 2 and b = 4.5.  
  
 
|-
 
|-
 
| 10:27
 
| 10:27
| What does ``print "a is modula d and b is'''<br/> Inline literal start-string without end-string.<br/> modula 2.1f" modula within brackets b comma a`` print?
+
| What does ``print "a is modula d and b is''' In line literal start-string without end-string. modula 2.1f" modula within brackets b comma a`` print?
 
** a is 2 and b is 4.5
 
** a is 2 and b is 4.5
 
** a is 4 and b is 2
 
** a is 4 and b is 2

Revision as of 17:21, 18 March 2013

Visual Cue Narration
0:00 Hello friends and welcome to this tutorial on 'Input/Output'.
0:05 At the end of this tutorial,you will be able to,
  1. Print some value.
  2. Print using modifiers.
  3. Take input from user.
  4. Display a prompt to the user before taking the input.
0:20 So type ipython on our terminal.
0:26 Type a = within double quotes This is a string
 Type a
 Type print a


0:45 obviously, print a , prints the value of a .
0:52 As you can see, even when you type just a, the value of a is shown.
0:59 But there is a difference.
1:01 Typing just a displays the content of a whereas the statement print a prints the string itself.
1:08 This difference becomes more evident when we use strings with newlines in them.
1:14 Type b = within double quotes A line backslash n New line and hit enter
Type b
Type print b
1:35 As you can see, just typing b shows that b contains a newline character but While typing print b,it prints the string and hence the newline.
1:46 Moreover when we type just a , the value a is shown only in interactive mode and does not have any effect on the program while running it as a script.
2:00 We shall look at different ways of outputting the data.
2:04 print statement in python supports string formatting.
2:08 Various arguments can be passed to print using modifiers.
2:12 type x = 1.5
      y = 2
      z = within double quotes red
      print   within double quotes x is modula 2 dot 1f comma  y is modula d comma  z is modula s then again a modula within brackets x comma y comma z


2:51 As you can see, the values of x, y and z are substituted in place of the modifiers modula 2.1f, modula d and modula s respectively.
3:03 Pause the video here, try out the following exercise and resume the video.
3:08 What happens when you do print within double quotes x is modula d comma y is modula f modula within brackets x comma y
3:19 Switch to the terminal for solution.
3:24 Type print within double quotes x is modula d comma y is modula f modula within brackets x comma y
3:50 We see that the int value of x and float value of y are printed corresponding to the modifiers used in the print statement.
3:58 We have seen that print statement prints a new line character every time it is called.
4:04 This can be suppressed by using a " comma " at the end of the print statement.
4:13 Let us see this by typing out following code on an editor as print underscore example.py
4:24 So Type..


4:44 print "Hello"
print "World"
print "Hello" comma 
print "World"
5:22 Save the script as 'print underscore example.py' and run it using modula run slash home slash fossee slash print underscore example.py
5:34 As we can see, the print statement when used with comma in the end, prints a space instead of a new line.
5:46 Now we shall look at taking input from the user.
6:06 We will use the ~~raw underscore input~~ for this.
6:11 So type ip = raw underscore input()
6:23 The cursor is blinking indicating that it is waiting for input, so type something and hit enter.
6:32 So you can type an input
6:35 Now let us see what is the value of ip by typing it.
6:41 So type ip and hit enter
6:45 We can see that it contains the string "an input"
6:51 Pause the video here, try out the following exercise and resume the video.
6:58 You have an question
7:02 Enter the number 5.6 as input and store it in a variable called c.
7:11 Switch to the terminal for solution.
7:15 We have to use the raw underscore input command with variable c.
7:19 So type c = raw underscore input() and hit enter
Put 5.6
And again enter.
Type c
7:36 Now let us see the type of c.
7:40 Type type within brackets c
7:46 We see that c is a string.
7:49 This implies that anything you enter as input, it will be taken as a string no matter what you enter.
7:55 Pause the video here, try out the following exercise and resume the video.
7:59 What happens when you do not enter anything and hit enter.
8:04 Switch to the terminal for solution.
8:08 Type d = raw underscore input()

<RET> d

8:28 We see that when nothing is entered, an empty string is considered as input.
8:32 raw underscore input also can display a prompt to assist the user.
8:37 So type name = raw underscore input within brackets within double quotes Please enter your name:
8:48 It prints the string given as argument and then waits for the user input.
8:54 Let us do one more exercise.
8:56 Pause the video here, try out the following exercise and resume the video.
9:00 How do you display a prompt and let the user enter input in next line.
9:09 Switch to the terminal for solution.
9:12 The trick is to include a newline character at the end of the prompt string.
9:17 Type ip = raw underscore input within brackets within double quotes Please enter a number in the next line backslash n>
9:28 It prints the newline character and hence the user enters input in the next line
9:35 This brings us to the end of the tutorial.
9:39 In this tutorial, we have learnt to,1. Use the print statement.
9:42 2. Use the modifiers modula d, modula f, modula s in the print statement.
9:47 3. Take input from user by using raw underscore input().
9:55 4. Display a prompt to the user before taking the input by passing a string as an argument to raw underscore input.
10:04 Here are some self assessment questions for you to solve
10:08 1. a = raw underscore input() and user enters 2.5 .
10:13 What is the type of a?
    • str
    • int
    • float
    • char
10:20 2. a = 2 and b = 4.5.
10:27 What does ``print "a is modula d and b is In line literal start-string without end-string. modula 2.1f" modula within brackets b comma a`` print?
    • a is 2 and b is 4.5
    • a is 4 and b is 2
    • a is 4 and b is 2.0
    • a is 4.5 and b is 2
10:50 And the answers,
10:53 1.No matter what you enter, it will be taken as a string.
10:58 Hence 2.5 is a string.
11:01 2. Since 'b' is called first, It will display integer value of 'a' because the modifier used is modula d.
11:10 Similarly, 'b' will get the float value of 'a' due to it's modifier modula 2.1f.
11:18 Hence 'a' will be 4 and 'b' 2.0 .
11:24 Hope you have enjoyed this tutorial and found it useful.

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha