Python-recap

Good Morning Boys!!


Today, we must begin the revision of Python and gradually move ahead with the  concepts of Python Programing for Class-10. 

Before I show you any example to recall Python programming, let's recall some steps to open the IDLE and work on it. 



Learning Outcomes

By the end of this blog you will be able to:


  • Recall the use of IDLE
  • Recapitulate some basic programs
  • Implement the knowledge of Python in making own program.

Writing a Python program

The following picture will remind you about the steps to open IDLE: 


The Python IDLE graphic window 
(Script Mode)
Typing and executing one command at time cannot be used for make big program. A programmer is always in need of a text editor in which she/he can easily type the whole code and then execute it after compiling. This is made possible because of Python IDLE graphic window.

IDLE is a default editor that comes with Python. After opening it you need to click on 'File' to open a 'New' code editor. This is where we can type Python programs. It allows to insert commands without executing them instantly. 

Let's see the following example:



Please note that in step: 3 File was saved and the Window of Step: 4 shows that the file was then named as test.py

In Final Output screen the output of test.py is visible. 




In the above example we have made a very small example. It's code is of just one line:

print("Hello", "World")


But I am sure you remember that we have done more that 12 programs in Class-9 (Session 2019-20).

For your reference, those programs are again sent to you through Redox App in the form of a Worksheet.


From the same worksheet, let's take Program No. - 10:

Please write heading (in your notebook or sheets):- Chapter-8: Python Revision

and write the following Question:

Q1. Write a program to take input of marks of a student in 5 subjects out of 100. Then show their Total and Percentage.


Answer: 

Now note the following code as an answer to the above question....




Once you execute this program, you will get the following output:-

Please note the output too...  



















You must have noticed that I have given 75, 82, 65, 92 and 46 as input for the Marks in 5 subjects respectively. 

Due to this the result has come as :- 

Total Marks : 360.0
Percentage : 72.0


This short program of Class-9 has helped us to recall the following: 

  • Use of Variables (as in this program they are- M1, M2, M3, M4, M5, Total and Per)
  • Use of assignment operator (i.e. = ) for assigning the values (in RHS) to a variable in (LHS).
  • Use of INPUT function (to accept the values from the user during run time/program execution time)
  • Use of FLOAT function (to type cast (convert) the values to Float type (i.e. with numbers with fractional part)
    If you remember in class 9 we had studied that the values received as input using INPUT function are always of String type first. Therefore we need to convert them to required type (i.e. we need to type cast them)
  • Use of Arithmetic operators (+, - , /, *, %, **) to make expressions for calculating the results. 
  • And finally The Use of PRINT function to given the output on the screen.

    Please note the print function is given with the value like this:
    ("Total Marks : ", Total)

    This means "Total Marks" is a String which will come as it is on the screen and Total is the variable whose value will be printed in front of the String ("Total Marks").
    Here comma (,) is working as concatenation operator i.e operator to join to values. 


Now, you may see this video to understand the above program in a practical way::::>>






(If the video doesn't play, click on Watch this video on Youtube which can be seen on the video screen)

Now before you join me in my next blog... Kindly work on the programs given in the worksheet. The worksheet is uploaded on Redox.


That's all for today

Thank you

God Bless You


Computer Science Department
(Middle School)

Comments

Post a Comment

Popular posts from this blog

Python-IF(Prac)

Python-IF command

Python- IF(2)