python-PROGRAM(1)


Good Morning Boys

Hope you are enjoying the journey of Python Programing

I would like to request you to mark your attendance by filling the form with the link below. Remember, if the registration number is entered incorrectly, attendance will not be allotted.



The answers to the EXERCISE given in the last session are as follows:

  1. >>>type(0)  output will be <class 'int'>
  2. >>>type(int(0))  output will be <class 'int'>
  3. >>>type(int('0')) output will be <class 'int'>
  4. >>>type('0') output will be <class 'str'>
  5. >>>type(1.0) output will be <class 'float'>
  6. >>>type(int(1.0)) output will be <class 'int'>
  7. >>>type(float(0)) output will be <class 'float'>
  8. >>>type(float(1.0)) output will be <class 'float'>
  9. >>>type(3/2) output will be <class 'float'>
---------------------------------------------------------
The Google meet ID for today's class is:

------------------------------------------------------
By the end of this session you will be able to:

  • Identify the output required as per the given question
  • Identify the input to be taken from the user
  • Define the variable(s) needed to solve the problem at hand
  • create a formatted output using the print command.
-----------------------------------------------------------

Today we will be doing some practical work during the class. Let us look at the first question from the Worksheet shared with you.


Q1. Write a program to print sum of two numbers which are 10 and 20.

a = 10
b = 20
c = a + b
print("The answer is ", c)


As you can see, we have 
1) created 2 variables- a and b
2) Assigned the value 10 to a and 20 to b
3) Found the sum of a and b (a+b) and assigned the result to  variable c
4) Display the message "The answer is " followed by the value of c. Don't miss the separator (punctuator)

The OUTPUT will be as follows:


 Please try above question on your computer.

------------------------------------------------------------

Let us take up the second question now.


Q2. Write a program to print total and average of 3 numbers which are 100, 200 and 300

A = 100
B = 200
C = 300
Tot = A+B+C
Avg = Tot/3

print("Total Marks are : ", Tot)
print("Average is ", Avg)

In the above program, as you can see, we have 
1) created 3 variables- a,b and c
2) Assigned the value 100 to a, 200 to b and 300 to c
3) Found the sum of a,b and c (i.e.a+b+c) and assigned the result to  variable Tot
4) Found the average using the formula Tot/3 (as there are 3 variables) and assign the result to variable Avg.
5) Display the message "Total marks are: " followed by the value of Tot. Don't miss the separator (punctuator).
6) Display the message "Average is: " followed by the value of Avg. Don't miss the separator (punctuator). 

The OUTPUT will be as follows:
Let us take up the next question now.


Write a program code to display your name.
 print("My name is Alex")  #EG1
 Nm = "Vijay"    #EG2
print("Hello! ", Nm)
Name = input("Enter your name : ")    #EG3

print("Hello! ", Name)

In the above set of statements, you can see, we are trying to dispaly the name of the user. 
In the statement (#EG1) i.e.

print("My name is Alex")  #EG1

The statement is not flexible and gives the same output each time it is executed, which is 
      My name is Alex.
-----------------------------------------------
In the statement (#EG2) i.e.

Nm = "Vijay"    #EG2
print("Hello! ", Nm)

The above set of statements are not flexible and give the same output each time it is executed which is 
         Hello Vijay
                                 
-----------------------------------------------
In the statement (#EG3) i.e.

Name = input("Enter your name : ")    #EG3

print("Hello! ", Name)

The above set of statements are comparatively more flexible. First statement accepts the value of name from the user and displays the message 
             Hello user_name
 each time it is executed, where user_name  is name entered by the user on execution of the program.           

The Combined output of the whole program is:
Let us take up the last question for the day.
#Python code to print area of circle.
R = float(input("Enter radius of the circle : "))
Area = 3.14*(R*R)

print("The area of the circle is : ", Area)

In the above program, as you can see, we have

1) created a variable  R
2) Accepted the value of radius of a circle , after displaying the message.
3)Typecast it to float
4)Assigned the value to a variable names R.
5) Created a variable named Area and assigned the value of 3.14*R*R (the formula to find the area of a circle).
4) Display the message "The area of the circle is :  " followed by the value of Area. Don't miss the separator (punctuator)

The OUTPUT will be as follows:

please try the above questions on your computer.
-----------------------------------------------------------
EXERCISE

Write a program in Python to accept the temperature in degree Fahrenheit and convert in degree Celsius.
(Formula-  °C =(°F - 32)/1.8)

Comments

  1. Good Morning Ma'am I am Joshua Walter of Class 9-D.

    ReplyDelete
  2. Good morning ma'am! Arjav Jain this side. I have successfully made the program.

    ReplyDelete
  3. The suitable code for the excercise will be:
    fahr= float(input("Enter the Fahrenheit measure: "))
    cels= (fahr-32)/1.8
    print("The temperature in celsius is", cels)

    ReplyDelete
  4. Good morning sir im bhavya 9D

    ReplyDelete

Post a Comment

Popular posts from this blog

HOLIDA'S HW

Introduction