Python- review(programs)




Good Morning Dear Students.





---------------------------------------------------------------------------------------
The Google Meet Link for today's session is:


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

  • Identify the common errors made in the coding of program given
  • Suggest possible solutions
  • identify and share doubts and difficulties being faced related to the topic
---------------------------------------------------------------------------------------- 
During the last session, you were given a form to share your responses to the following question:

Write a program in Python to accept two numbers (num1 and num2) from the user, typecast them to integer and then find sum and product of the two.

Please note that the above question has 5 steps:

  1. accepting two numbers from the user
  2. typecasting them to integer
  3. find their sum 
  4. find their product
  5. Display the results
Let me take the opportunity of sharing few responses with you:

Response 1

num_1 = int(23)23 
num_2 = int(13.83)
print( num_1 + num_2)
print( num_1 * num_2)      

FEEDBACK: 
The above program is NOT FLEXIBLE. Every time it  get executed, it works with the values 
and 13.83. Also, no messages are shared while displaying result. Though this will not be shown as an error, but reflects poor programing technique
-------------------------------------------------------------------------------------------------------
Response 2
num1=input(int(enter a number) #1
num2=input(int(enter another number) #2
x = (num1,num2)       #3
print (x) #4
y = (num1*num2)   #5
print (y)  #6

FEEDBACK: 
1. The above program will give a syntax error (Incorrect way of writing) as the phrase ENTER A NUMBER in the first statement must be enclosed within a single or a double quote sign. So this error is seen in #1 and #2
2. Also, the number of brackets in #1 and #2 statements are not balanced. this is also a syntax error.
3. In statement #3, (num1,num2) does not signify anything.  It should calculate sum and is not doing the same.
4. In statement #4, appropriate message for the reader is missing, though this is not an error.
 5. In statement #6, appropriate message for the reader is missing, though this is not an error.
---------------------------------------------------------------------------------------------------------
Response 3
num1=int("10")   #1
num2=int("5")  #2
sum="num1+num2"  #3
product="num1*num2"   #4
print("sum")    #5
print("product")   #6

FEEDBACK: 
1. The above program statements #1,#2,#3 and #4 give a clear reflection that the person doing coding is not clear about the concept of numbers and string constants as "10" ,"5", "num1+num2" and "num1*num2" are all string constants, and so will be printed as they are.
2. Likewise in statement #5, print("sum") will give the output
       sum 
  as it is enclosed in quotes
3. Likewise in statement #6, print("product") will give the output
       product
  as it is enclosed in quotes
-----------------------------------------------------------------------------------------------------------

MODEL ANSWER:


num1= int(input("Enter the first number:  "))
num2= int(input("Enter the second number:  "))
sum= num1+num2
product= num1*num2
print("The sum of the 2 numbers is: ",sum)
print("The product of the 2 numbers is: ",product)          


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

Now, let us discuss the question given as HW exercise:

Write a program in Python to accept height in feet and convert to inches.

print("Input your height: ") h_ft = int(input("Feet: ")) h_inch = int(input("Inches: ")) h_inch = h_inch + h_ft * 12
print("Your height in inches is : ", h_inch)

The above program will look like this in the PYTHON window:
and on execution, we will get the following result:


------------------------------------------------------------------
Let us now look at doubts, if any.

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

An assessment based on Python Programing is scheduled for tomorrow.So, there will be no Google meet class tomorrow.  Please prepare well.All the Best!!!! 

Comments

  1. feet = input('enter your height(in feet): ')
    inch = (feet * 5)
    print('your height in inches is: ', inch)

    ReplyDelete
  2. Mam what do we have to write

    ReplyDelete

Post a Comment

Popular posts from this blog

HOLIDA'S HW

Introduction

python-PROGRAM(1)