UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Writing Simple programs in Python(cont.)

Ashish K Sharma
29/11/2021 0 0

To start writing simple programs in Python, we have to know firstly the SW development process and then we also have to know a bit about the language in which we wish to code,in this case,python, to get started. Since all programs take some kind of input,process it and then produce the results,if we know just how to get data from the user,process it and produce output in a readable form, we would be well on the road to learning how to code. We begin by looking at the notion of a variable.

                                            

                                                              What is a variable?

Simply stated,a variable is name assigned to a value. For example, 

                                                               n = 5

here, n is a variable given the value 5.Whenever n appears in an expression, its value,5 will be substituted. Now,let us take a look at some basic mathematical operators in Python.

 

                                                         Some basic Arithmetic Operators.

                                             + = Addition

                                              - = Subtraction

                                             * = Multiplication

                                             / = Division

                                            ** = Exponentiation.

Now,we will look at basic I/O.

 

                                                       Basic I/O

In order to get information from the user, Python uses the input statement,as shown below

                                               name = input("Enter your name:")

This statement,when executed by the Python interpreter,display the string within quotes,prompting the user to enter his name,as shown below:

                                         Enter your name:Rajesh

Here,Rajesh is our response.

Now, to display information to the user, we use the function print. It may be used just to display a message or output the value of a variable or a result of some processing or to display a combination of some strings and variables.

 

Thus, in Python, input is used to get information from the user and print is used to display information on the screen.

In my earlier lesson, we saw a program in Python which calculates the future value of an investment. Those of you who could not fully understand the program then now will be able to,in light of the elements discussed here(I/O statements,operators etc),comprehend fully the program now. Let us take another example of a simple program in python which calculates the Fahrenheight equivalent of a given celsius temperature. Our program should take a celsius temperature from the user and then print the fahrenheight equivalent. Simple! The algorithm of the program is:

                                     Input the temperature in degrees Celsius (call it celsius)
                                     Calculate fahrenheit as 9/5 celsius + 32
                                     Output fahrenheit.

 

And the full program in Python:

                     Note:Take input from the user.

                     cel = input("What is the Celsius Temperature")

                     x = 9/5
                     y = x * int(cel)

                     fint = y + 32

                     Note: I have broken the formula of calculating celsius temperature into fahrenheight into 

                             steps for easy calculation. int(cel) is used for converting the value into an int. I have 

                             used it my interpreter,Python 3.3.1 which was not interpreting it correctly without the 

                            int conversion.

                      Note : Display output.
                     print("Fahrenheight Temperature = "+str(fint))

                                         

 So,thus,I hope that users will now be able to start writing simple programs in Python on their own. Of course this is just the beginning! As they progress and learn more details of the language, they will be able to write more sophisticated programs in Python!

 

Note : Here and in my earlier lesson, I have assumed that students know how to start the IDLE of Python and write and run a program in it. Although the process is quite simple I intend, in the next lesson, to teach students how to create and run a Python Program using the Python IDLE,in case they dont know! Not only we must know the language reading from a book,we must also know how to write a program in it,run it and test it! And with that Students will be able to write simple programs easily enough!

 

 

             

 

  

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Python breaks into the top three programming languages in the Tiobe Index for the first time.
Python breaks into the top three programming languages in the Tiobe Index for the first time. The popularity of Python shows no sign of waning, with the programming language entering the top three in...

Top Programming Languages 2017: Every Beginner Should Learn
Every year a plethora of job opportunities are being created for skilled programmers. So if you are thinking of honing your coding skills it is really a bright idea. But with so many programming languages...

All About Python You Need To Know Before Starting
Python for Beginners------Anyone can learn Python Prerequisites to learn Python To learn Python we don’t require the knowledge of any other programming languages. To learn all other programming...

Different types of data in python3
Python3 features Numbers(int,float,complex), String, Lists, Tuples, Dictionary and Sets type of data. long interger type numbers from python2 is no longer required. Below are examples of all python3 data...

Python programming - Applications
If you’re thinking of learning Python? Or if you recently started learning it? You may be asking yourself: "What exactly can I use Python for?" There are so many applications for python, but there...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more