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

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Visual Cue
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
| 0:00
+
| 00:00
 
| Hello friends and welcome to this tutorial on 'Input/Output'.
 
| Hello friends and welcome to this tutorial on 'Input/Output'.
  
 
|-
 
|-
| 0:05
+
| 00:05
 
| At the end of this tutorial,you will be able to,
 
| At the end of this tutorial,you will be able to,
  
Line 16: Line 16:
  
 
|-
 
|-
| 0:20
+
| 00:20
 
| So type ipython in the terminal.
 
| So type ipython in the terminal.
 +
 
|-
 
|-
| 0:26
+
| 00:26
 
| Type a = within double quotes This is a string
 
| Type a = within double quotes This is a string
 
   Type a
 
   Type a
 
   Type print a
 
   Type print a
 
  
 
|-
 
|-
| 0:45
+
| 00:45
 
| obviously,  print a , prints the value of a .
 
| obviously,  print a , prints the value of a .
  
 
|-
 
|-
| 0:52
+
| 00:52
 
| As you can see, even when you type just a, the value of a is shown.
 
| As you can see, even when you type just a, the value of a is shown.
  
 
|-
 
|-
| 0:59
+
| 00:59
 
| But there is a difference.
 
| But there is a difference.
  
 
|-
 
|-
| 1:01
+
| 01:01
 
| Typing just  a  displays the content of  a  whereas the statement  print a  prints the string itself.  
 
| Typing just  a  displays the content of  a  whereas the statement  print a  prints the string itself.  
  
 
|-
 
|-
| 1:08
+
|01:08
 
| This difference becomes more evident when we use strings with newlines in them.
 
| This difference becomes more evident when we use strings with newlines in them.
  
 
|-
 
|-
|1:14
+
|01:14
 
|Type b =  within double quotes A line backslash n New line and hit enter
 
|Type b =  within double quotes A line backslash n New line and hit enter
 
  Type b
 
  Type b
Line 52: Line 52:
  
 
|-
 
|-
| 1:35  
+
| 01: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.
 
| 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
+
| 01: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.
 
| 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
+
| 02:00
 
| We shall look at different ways of outputting the data.
 
| We shall look at different ways of outputting the data.
  
 
|-
 
|-
| 2:04
+
| 02:04
 
| print statement in python supports string formatting.  
 
| print statement in python supports string formatting.  
  
 
|-
 
|-
| 2:08
+
| 02:08
 
| Various arguments can be passed to print using modifiers.
 
| Various arguments can be passed to print using modifiers.
  
 
|-
 
|-
| 2:12
+
| 02:12
 
| type x = 1.5
 
| type x = 1.5
 
       y = 2
 
       y = 2
Line 80: Line 80:
  
 
|-
 
|-
| 2:51
+
| 02: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.
 
| 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
+
| 03:03
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
| 3:08
+
| 03:08
 
| What happens when you do print  within double quotes x is modula d comma  y is modula f modula  x comma  y
 
| What happens when you do print  within double quotes x is modula d comma  y is modula f modula  x comma  y
 
|-
 
|-
| 3:19
+
| 03:19
 
| Switch to the terminal for solution.
 
| Switch to the terminal for solution.
  
 
|-
 
|-
|3:24
+
|03:24
 
| Type print  within double quotes x is modula d comma  y is modula f modula within brackets x comma  y
 
| Type print  within double quotes x is modula d comma  y is modula f modula within brackets x comma  y
  
 
|-
 
|-
| 3:50
+
| 03: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.
 
| 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
+
| 03:58
 
| We have seen that print statement prints a new line character every time it is called.  
 
| We have seen that print statement prints a new line character every time it is called.  
  
 
|-
 
|-
| 4:04
+
| 04:04
 
| This can be suppressed by using a " comma " at the end of the print statement.
 
| This can be suppressed by using a " comma " at the end of the print statement.
  
 
|-
 
|-
| 4:13
+
| 04:13
 
| Let us see this by typing out following code on an editor as print underscore example.py
 
| Let us see this by typing out following code on an editor as print underscore example.py
  
 
|-
 
|-
| 4:24
+
| 04:24
 
| So Type..
 
| So Type..
 
  
 
|-
 
|-
|4:44
+
|04:44
 
|print "Hello"
 
|print "Hello"
 
  print "World"
 
  print "World"
Line 128: Line 127:
  
 
|-
 
|-
| 5:22
+
| 05:22
 
| Save the script as 'print underscore example.py' and run it using modula run  slash home slash fossee slash print underscore example.py
 
| 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
+
| 05:34
 
| As we can see, the print statement when used with comma in the end, prints a space instead of a new line.
 
| As we can see, the print statement when used with comma in the end, prints a space instead of a new line.
  
 
|-
 
|-
| 5:46
+
| 05:46
 
| Now we shall look at taking input from the user.  
 
| Now we shall look at taking input from the user.  
  
 
|-
 
|-
| 6:06
+
| 06:06
 
| We will use the ~~raw underscore input~~ for this.
 
| We will use the ~~raw underscore input~~ for this.
  
 
|-
 
|-
|6:11
+
|06:11
 
|So type ip = raw underscore input()  
 
|So type ip = raw underscore input()  
  
 
|-
 
|-
| 6:23
+
| 06:23
 
| The cursor is blinking indicating that it is waiting for input, so type something and hit enter.
 
| The cursor is blinking indicating that it is waiting for input, so type something and hit enter.
  
 
|-
 
|-
|6:32
+
|06:32
 
|So you can type an input
 
|So you can type an input
  
 
|-
 
|-
| 6:35
+
| 06:35
 
| Now let us see what is the value of ip by typing it.
 
| Now let us see what is the value of ip by typing it.
  
 
|-
 
|-
|6:41
+
|06:41
 
|So type ip on the terminal and hit enter
 
|So type ip on the terminal and hit enter
  
 
|-
 
|-
| 6:45
+
| 06:45
 
| We can see that it contains the string "an input"
 
| We can see that it contains the string "an input"
  
 
|-
 
|-
| 6:51
+
| 06:51
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
| 6:58
+
|06:58
 
| You have an question
 
| You have an question
  
 
|-
 
|-
| 7:02
+
| 07:02
 
| Enter the number 5.6 as input and store it in a variable called c.
 
| Enter the number 5.6 as input and store it in a variable called c.
  
 
|-
 
|-
7:11
+
07:11
 
| Switch to the terminal for solution.
 
| Switch to the terminal for solution.
  
 
|-
 
|-
| 7:15
+
| 07:15
 
| We have to use the raw underscore input command with variable c.  
 
| We have to use the raw underscore input command with variable c.  
  
 
|-
 
|-
|7:19
+
|07:19
 
|So type c = raw underscore input() and hit enter
 
|So type c = raw underscore input() and hit enter
 
  Put 5.6
 
  Put 5.6
Line 195: Line 194:
  
 
|-
 
|-
| 7:36
+
| 07:36
 
| Now let us see the type of c.
 
| Now let us see the type of c.
  
 
|-
 
|-
|7:40
+
|07:40
 
|Type type within brackets c
 
|Type type within brackets c
  
 
|-
 
|-
| 7:46
+
| 07:46
 
| We see that c is a string.  
 
| We see that c is a string.  
  
 
|-
 
|-
| 7:49
+
| 07:49
 
| This implies that anything you enter as input, it will be taken as a string no matter what you enter.
 
| This implies that anything you enter as input, it will be taken as a string no matter what you enter.
  
 
|-
 
|-
| 7:55
+
| 07:55
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
| 7:59
+
| 07:59
 
| What happens when you do not enter anything and hit enter.
 
| What happens when you do not enter anything and hit enter.
  
 
|-
 
|-
| 8:04
+
| 08:04
 
| Switch to the terminal for solution.
 
| Switch to the terminal for solution.
  
 
|-
 
|-
|8:08
+
|08:08
 
|  Type d = raw underscore input()
 
|  Type d = raw underscore input()
 
<RET>
 
<RET>
Line 229: Line 228:
  
 
|-
 
|-
| 8:28
+
| 08:28
 
| We see that when nothing is entered, an empty string is considered as input.
 
| We see that when nothing is entered, an empty string is considered as input.
  
 
|-
 
|-
| 8:32
+
| 08:32
 
| raw underscore input also can display a prompt to assist the user.
 
| raw underscore input also can display a prompt to assist the user.
  
 
|-
 
|-
|8:37
+
|08:37
 
|So type name = raw underscore input within brackets  within double quotes Please enter your name:   
 
|So type name = raw underscore input within brackets  within double quotes Please enter your name:   
  
 
|-
 
|-
| 8:48
+
| 08:48
 
| It prints the string given as argument and then waits for the user input.
 
| It prints the string given as argument and then waits for the user input.
  
 
|-
 
|-
| 8:54
+
| 08:54
 
| Let us do one more exercise.
 
| Let us do one more exercise.
  
 
|-
 
|-
| 8:56
+
| 08:56
 
|  Pause the video here, try out the following exercise and resume the video.
 
|  Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
| 9:00
+
| 09:00
 
| How do you display a prompt and let the user enter input in next line.
 
| How do you display a prompt and let the user enter input in next line.
  
 
|-
 
|-
| 9:09
+
| 09:09
 
| Switch to the terminal now.  
 
| Switch to the terminal now.  
  
 
|-
 
|-
| 9:12
+
| 09:12
 
| The trick is to include a newline character at the end of the prompt string.
 
| The trick is to include a newline character at the end of the prompt string.
  
 
|-
 
|-
|9:17
+
|09:17
 
|Type ip = raw underscore input within brackets  within double quotes Please enter a number in the next line backslash n
 
|Type ip = raw underscore input within brackets  within double quotes Please enter a number in the next line backslash n
  
 
|-
 
|-
| 9:28
+
| 09:28
 
| It prints the newline character and hence the user enters input in the next line
 
| It prints the newline character and hence the user enters input in the next line
  
 
|-
 
|-
| 9:35
+
| 09:35
 
| This brings us to the end of the tutorial.  
 
| This brings us to the end of the tutorial.  
  
 
|-
 
|-
| 9:39
+
| 09:39
 
| In this tutorial, we have learnt to,1. Use the print statement.
 
| In this tutorial, we have learnt to,1. Use the print statement.
  
 
|-
 
|-
| 9:42
+
| 09:42
 
| 2. Use the modifiers modula d, modula f, modula s in the print statement.
 
| 2. Use the modifiers modula d, modula f, modula s in the print statement.
  
 
|-
 
|-
| 9:47
+
| 09:47
 
| 3. Take input from user by using raw underscore input().
 
| 3. Take input from user by using raw underscore input().
  
 
|-
 
|-
| 9:55
+
| 09:55
 
| 4. Display a prompt to the user before taking the input by passing a string as an argument to raw underscore input.
 
| 4. Display a prompt to the user before taking the input by passing a string as an argument to raw underscore input.
  

Revision as of 15:04, 10 July 2014

Time Narration
00:00 Hello friends and welcome to this tutorial on 'Input/Output'.
00: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.
00:20 So type ipython in the terminal.
00:26 Type a = within double quotes This is a string
 Type a
 Type print a
00:45 obviously, print a , prints the value of a .
00:52 As you can see, even when you type just a, the value of a is shown.
00:59 But there is a difference.
01:01 Typing just a displays the content of a whereas the statement print a prints the string itself.
01:08 This difference becomes more evident when we use strings with newlines in them.
01:14 Type b = within double quotes A line backslash n New line and hit enter
Type b
Type print b
01: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.
01: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.
02:00 We shall look at different ways of outputting the data.
02:04 print statement in python supports string formatting.
02:08 Various arguments can be passed to print using modifiers.
02:12 type x = 1.5
      y = 2
      z = within double quotes red
      print  then in 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


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

<RET> d

08:28 We see that when nothing is entered, an empty string is considered as input.
08:32 raw underscore input also can display a prompt to assist the user.
08:37 So type name = raw underscore input within brackets within double quotes Please enter your name:
08:48 It prints the string given as argument and then waits for the user input.
08:54 Let us do one more exercise.
08:56 Pause the video here, try out the following exercise and resume the video.
09:00 How do you display a prompt and let the user enter input in next line.
09:09 Switch to the terminal now.
09:12 The trick is to include a newline character at the end of the prompt string.
09:17 Type ip = raw underscore input within brackets within double quotes Please enter a number in the next line backslash n
09:28 It prints the newline character and hence the user enters input in the next line
09:35 This brings us to the end of the tutorial.
09:39 In this tutorial, we have learnt to,1. Use the print statement.
09:42 2. Use the modifiers modula d, modula f, modula s in the print statement.
09:47 3. Take input from user by using raw underscore input().
09: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