0% found this document useful (0 votes)
14 views

Input Data

Uploaded by

Rishta Porwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Input Data

Uploaded by

Rishta Porwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ARYA VIDYA MANDIR GROUP OF SCHOOLS

STD VIII Computer


input()

Introduction
We have seen how we can store values in names or associate names with
values using the assignment operator (=). The drawback or limitation of using the ‘=’
operator as a means to associate names and values is that every time the program is
executed, the same values are used for the calculation and hence the same result is
obtained.

Example:
n1=25
n2=30
sum = n1+n2
print('Sum=',sum)

Every time that we execute the program, we will get the same result i.e. 55. But, what if
we want to calculate the sum of different set of values (such as 112, 352; 77, 35 ;
427,835) each time that the program is executed.

In order to get different results, we will be required to make changes to the


program every time and then execute it.

But, this is not required when we use the input statement instead of the
association operator(=). With input statements, the values for the program are not
provided in the program but they are provided during program execution. Hence, we
can use the same program without making any changes, to obtain a different result
each time that the program is executed.

Example
n1=int(input('Enter first number'))
n2=int(input('Enter second number'))
sum=n1+n2
print('Sum=',sum)

As is clear, in the above program, no values are specified.

The steps in which values are assigned to the variables are :


1. Execute the program

1 | Page
2. When the message “ Enter first number” is displayed, type in an integer value
and press the enter key
3. Similarly for the 2nd number.

Please note that the message “Enter first number” is displayed only because we
have included it in our program. If we do not include it or specify it, there will be no
message displayed but the computer will wait for us to type in an integer value for the
1st input() and another integer value for the 2nd input() . A message is essential so that
during program execution we know what response the computer expects from us.

Note: Whenever values are given in the question, the assignment operator (=) must be
used to assign the values; otherwise input() must be used.

Write programs for the following:


1. To accept four numbers from the user and calculate and print their sum.
2. To accept two numbers from the user and calculate and print their product and
difference.
3. You are given that the rate of pens is Rs. 20/- each and pencil is Rs. 3/- each.
Accept from the user the quantity purchased of each of them and calculate and
print the amount to be paid to the shopkeeper.
4. Accept from the user the scores obtained by 3 students in a G.K. Quiz and
calculate and print their average score.
5. You are given that the rate of tomatoes is Rs. 15/ kg and beans is Rs. 30/kg;
Ask the user the quantity that he wishes to purchase of each vegetable and print
the total amount to be paid.
6. Accept from the user the name of the student and scores obtained in six
subjects. The maximum marks for each subject are 25. Calculate and print the
total marks as well as the percentage along with the name.
Percentage = Total marks obtained x100
Total of maximum marks
7. You are given that a bank pays interest @ 9% on fixed deposit. Accept from the
user the amount he would like to deposit and the time period and calculate and
print the interest and the final amount. SI=(pr*r*t)/100
8. Accept from the user the quantity purchased of an item and its rate and calculate
and print the total bill.

2 | Page

You might also like