# Property Painting Coding Question

## TCS Coding Question Day 2 Slot 1 : Question 1

This question has been asked in the TCS NQT 2020 Day 2 Slot 1

Topic : Conditional Statement

Time Given : 15 Minutes

Difficulty : 2/5 stars

We want to estimate the cost of painting a property. Interior wall painting cost is Rs.18 per sq.ft. and exterior wall painting cost is Rs.12 per sq.ft.

Take input as
1. Number of Interior walls
2. Number of Exterior walls
3. Surface Area of each Interior 4. Wall in units of square feet
Surface Area of each Exterior Wall in units of square feet

If a user enters zero  as the number of walls then skip Surface area values as User may don’t  want to paint that wall.

Calculate and display the total cost of painting the property
Example 1:

6
3
12.3
15.2
12.3
15.2
12.3
15.2
10.10
10.10
10.00
Total estimated Cost : 1847.4 INR

Note: Follow in input and output format as given in above example

`#include<stdio.h>int main(){    int ni,ne,i=0;    float int_p=18,ext_p=12,cost=0,temp;    scanf("%d %d",&ni,&ne);    if(ni<0 || ne<0 )    {        printf("INVALID INPUT");    }    else if(ni==0 && ne==0)    {        printf("Total estimated Cost : 0.0");    }    else    {        for(i=0;i<ni;i++)        {            scanf("%f",&temp);            cost+= int_p*temp;        }        for(i=0;i<ne;i++)        {            scanf("%f",&temp);            cost+= ext_p*temp;        }        printf("Total estimated Cost : %.1f",cost);    }    return 0;}`
`#include<iostream>using namespace std;int main(){    int ni,ne,i=0;    float int_p=18,ext_p=12,cost=0,temp;    scanf("%d %d",&ni,&ne);    if(ni<0 || ne<0 )    {        cout<<"INVALID INPUT";    }    else if(ni==0 && ne==0)    {        cout<<"Total estimated Cost : 0.0";    }    else    {        for(i=0;i<ni;i++)        {            cin>>temp;            cost+= int_p*temp;        }        for(i=0;i<ne;i++)        {            cin>>temp;            cost+= ext_p*temp;        }        cout<<"Total estimated Cost : "<<cost;          }    return 0;}`
`interior_walls = int(input())exterior_walls = int(input())if interior_walls:    int_walls = []    for i in range(interior_walls):        int_walls.append(float(input()))if exterior_walls:    ext_walls = []    for i in range(exterior_walls):        ext_walls.append(float(input()))if exterior_walls < 0 or interior_walls < 0:    print(“Invalid Input”)    exit()if exterior_walls and interior_walls:    print("Total estimated Cost : ",(sum(int_walls)*18+sum(ext_walls)*12),"INR")else:    if exterior_walls:        print("Total estimated Cost : ",sum(ext_walls)*12,"INR")    elif interior_walls:         print("Total estimated Cost : ",sum(int_walls)*18,"INR")    else:        print("Total estimated Cost : 0.0 INR")`
`import java.util.Scanner;class Main {    public static void main(String[] args) {       int ni, ne, i = 0;       float intP = 18, extP = 12, cost = 0, temp;       Scanner sc = new Scanner(System.in);       ni = sc.nextInt();       ne = sc.nextInt();       if(ni < 0 || ne < 0) {           System.out.print("INVALID INPUT");       } else if(ni == 0 && ne == 0) {           System.out.print("Total estimated Cost : 0.0");       } else {           for(i = 0; i < ni; i++) {               temp = sc.nextFloat();               cost += intP * temp;           }           for(i = 0; i < ne; i++) {               temp = sc.nextFloat();               cost += extP * temp;           }           System.out.printf("Total estimated Cost : %.1f", cost);       }    }}`

## Day 2 Slot 1 Question 2

Click on the below button to study Day 2 Slot 2 Question 1 of TCS NQT Coding 2020 exam

Code

## TCS Coding Questions

Click on the below button to study more TCS Coding Question

TCS Coding Question

### 2 comments on “Property Painting Coding Question”

• Yash

int_wall=int(input())
ext_wall=int(input())
iwall=[]
ewall=[]
for i in range(int_wall):
iwall.append(float(input()))
for i in range(ext_wall):
ewall.append(float(input()))
isum=sum(iwall)*18
esum=sum(ewall)*12
print(“Total estimated cost: {}”.format(isum+esum))

• MAYANK

interior_walls = []
exterior_walls = []

a = int(input(‘Enter the number of interior walls : ‘))
b = int(input(‘Enter the number of exterior walls : ‘))

for i in range(a):
interior_walls.append(float(input(‘Surface area of interior walls : ‘)))

for i in range(b):
exterior_walls.append(float(input(‘Surface area of exterior walls : ‘)))

print(interior_walls)
print(exterior_walls)

sum1 =0
sum2 =0

for i in interior_walls:
sum1 = sum1 + i
i +=1

for i in exterior_walls:
sum2 +=i
i+=1

if a<0 or b<0:
print('Invalid Input')
exit()

if a and b :
print('Total cost to paint both the walls are ', (sum1*18 + sum2*12),"INR")

else:
if a :
print('Cost to paint interior walls are ', sum1*18,"INR")
elif b:
print('Cost to paint exterior walls are ', sum2*12,"INR")
else:
print('Toatka cost estimated 0.0 INR')