Difference between revisions of "Python-3.4.3/C3/Input-output/English"
Nancyvarkey (Talk | contribs) |
|||
Line 150: | Line 150: | ||
|- | |- | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Type x = 1. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Type x = 1.56789 |
print('The value of x is %3.2f' %x) | print('The value of x is %3.2f' %x) | ||
Highlight %3.2f | Highlight %3.2f | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.097cm;padding-right:0.191cm;"| Next let us assign x as shown. |
Line 430: | Line 430: | ||
− | Type '''ip '''''is equal to''''' input '''''inside parentheses inside double quotes '''''Please enter a number ''''' | + | Type '''ip '''''is equal to''''' input '''''inside parentheses inside double quotes '''''Please enter a number '''''slash''''' n''' |
|- | |- |
Revision as of 12:57, 24 May 2018
|
|
Show Slide Title | Welcome to the spoken tutorial on Input and Output. |
Show Slide
Learning Objectives |
In this tutorial, we will learn to
|
Show Slide
System Specifications |
To record this tutorial, I am using
|
Show Slide
Pre-requisite slide |
To practise this tutorial,
If not, see the relevant Python tutorials on this website. |
[Terminal]
ipython3 |
Let us start ipython.
|
Type, a = "This is a string" | Let us start this tutorial with a string.
|
Type, a | To see the value of a, type, a |
Type, print (a)
|
Type, print inside parentheses a
|
Type, b = "A line \n New line" | Now type b is equal to inside double quotes A line \n New line |
Type, b
|
Type, b
|
Type, print (b)
|
Type, print inside parentheses b
|
Slide:
Formatting operations |
Next we shall look at different ways of outputting the data.
|
Switch back to the terminal. | |
Type x = 1.56789
print('The value of x is %3.2f' %x) Highlight %3.2f |
Next let us assign x as shown.
|
print('The value of x is %3.4f' %x)
|
We will see one more example.
|
Type, y = 2 | Next, let us assign two more values.
|
Type, z = "red" | z is equal to inside double quotes red |
Highlight
Type, print (''x is %2.1f, y is %d, z is %s''%(x,y,z))
|
To print the value of x, y and z, type as shown.
respectively.
|
Show Slide
|
Pause the video.
|
Switch the terminal | Switch to the terminal for the solution. |
Type, print (''x is %d, y is %f'' %(x, y))
|
Type as shown.
|
Open text editor and type
print ("Hello") print ("World") print ("Hello",end=' ') print ("World") |
Usually print statement prints the output in a new line.
|
Highlight end=' ' | The newline character can be suppressed by passing end is equal to inside single quotes a space. |
Save it as print_example.py | Save the script as print underscore example.py. |
Switch to the terminal | Switch back to the terminal. |
Type %run print_example.py
|
Let us run the code by typing percentage run space print underscore example.py
|
Type, ip = input() | Next we shall look at taking input from the user.
|
Point the input cursor
|
The cursor is blinking indicating that it is waiting for an input.
|
Type, ip
|
Now let us see what is the value of ip.
|
Show Slide
|
Pause the video.
|
Switch to terminal | Switch back to the terminal for the solution. |
Type, c = input() | We have to use the input command with variable c.
|
Enter 5.6 | Enter 5.6 as input. Press Enter. |
Type, c | To see the input value, type c |
Type, type(c)
|
Now let us see the date type of c.
|
Show Slide
|
Pause the video.
|
Switch to terminal | Switch back to the terminal for the solution. |
Type, d = input()
|
Type d is equal to input open and close parentheses
Again press Enter to get the prompt. |
Type, d
|
To see the input value, type, d
|
Type, ip = input("Please enter a number\n ") | We can also use input to display a prompt to assist the user.
|
Enter 12 | I will give 12 as input.
|
Show Slide
Summary slide
|
This brings us to the end of this tutorial. Let us summarise.
|
Show Slide
Evaluation
|
Here are some self assessment questions for you to solve
|
Show Slide
|
And the answers,
Similarly, float value of a will be displayed due to its modifier percentage 2.1f. Hence the output is a is 4 and b is 2.0 |
Slide Forum | Please post your timed queries in this forum. |
Slide Fossee Forum | Please post your general queries on Python in this forum. |
Slide Textbook Companion | FOSSEE team coordinates the TBC project. |
Show Slide
Acknowledgement |
Spoken-tutorial is funded by NMEICT, MHRD, Govt. of India.
|
Show Slide
Thank You |
This is Priya from IIT Bombay signing off.
|