Skip to main content

VIT SKILLRACK SOLUTIONS

     VIT SKILLRACK SOLUTIONS WITH        PSEUDOCODES


PPS 1 FALL 18

Q1) Design an algorithm and draw a flow chart to check the given number is Armstrong number of three digits or not. A number is said to be Armstrong number if the summation of cube of digits in a three digit number is equal to the number. Check for boundary conditions, if the value entered is outside boundary conditions then enter 'Invalid input'.

Code:
n=int(input('Enter the three digit number:'))
if(len(str(n))==3 and n>=100 and n<=999):
while(m):
s=s+(m%10)**3
m=m//10
if(s==n):
print('Yes')
else:
print('No')
else:
print('Invalid')

Input:
A number 'n'

Processing:
if(len(str(n))==3 and n>=100 and n<=999):
while(m):
s=s+(m%10)**3
m=m//10
if(s==n):
print('Yes')
else:
print('No')
else:
print('Invalid')

Output:
Print Armstrong or Not armstrong

Pseudo Code:
START
1) Read the number 'n'
2) s=0, m=n
3) if(len(str(n))==3 and n>=100 and n<=999), continue
4) while(m), s=s+(m%10)**3 and m=m//10 => Finding the sum of the cubes of digits
5) if n==s, print('Armstrong') else print('Not armstrong')
6) Else print('Invalid input')
END

Flow Chart:



Q2) Devise an algorithm and draw a flowchart to simulate the working of an AND gate. AND gate takes two bits as input and output a bit as shown in the following table. Check for validity of input and print ‘Invalid input’ when user gives out of boundary values

Code:
x=int(input())
y=int(input())
if(x==1 or x==0 and y==1 or y==0):
  if(x==1 and y==1):
     print(1)
  else:
     print(0)
else:
    print('Invalid input')

Input:
Read two bits 'x' and 'y'

Processing:
if(x==1 and y==1):
     print(1)
else:
     print(0)

Output:
Print 0 or 1

Pseudo Code:
START
1) Read two bits 'x' and 'y'
2) If x=0 or x=1 continue, else print 'Invalid input'
3) If x=0 or x=1 continue, else print 'Invalid input'
4) if x=1 and y=1, print 1
5) else, print 0
END


Flow Chart:



Q3) A health drink company, gives a festival offer to its retail customers. The health drink is packed in 1 kg pack. For every 5, one kg pack purchase, one 1kg pack will be free. (i.e. buy 5 get 1 free). Given the number of health drink packets purchased, design an algorithm and draw a flowchart to determine the total number of packets that the customer will get.

Code:

packets=int(input())
if(packets>0 and packets<=500):
   free = packets//5
   total = packets + free
   print(total)
else:
   print('Invalid input')


Input:
Number of health drink packets purchased

Processing:
if(n>0 and n<=500):
   free = packets//5
   total = packets + free
   print(total)
else:
   print('Invalid input')
Output:
Print the Total number of packets that the customer will get.

Pseudo Code:
START
1) Read the number of packets purchased 'n'
2) if n>0 and n<=500 ,continue else print 'Enter valid number of packets'
3) free = packets//5
4) total = packets + free
5) print (total)
END

Flow Chart:



Q4) Every day morning and evening milk is brought from ‘n’ farms to a milk booth for sales. Given the amount of milk from ‘n’ farms, write an algorithm to compute total quantity of milk in the booth. For example, if milk comes from 3 farms in quantities 2 litres 300ml, 3 litres 700ml and 4 litres 600ml then the total quantity of milk in booth is 10litre 600ml.

Code:
n=int(input())
ml=0
for i in range(n):
K=int(input())
m=int(input())
ml=ml+m+K*1000
litre=ml//1000
ml=ml%1000
print(str(litre)+'litre'+str(ml)+' '+'ml')


Input:
Number of farms 'n'
Amount of milk from each of the 'n' farms

Processing:
for i in range(n):
K=int(input())
m=int(input())
ml=ml+m+K*1000
litre=ml//1000
ml=ml%1000


print(str(litre)+'litre'+str(ml)+' '+'ml')
Output:
Print the total quantity of milk in booth

Pseudo Code:
START
1) Read the number of farms
2) let count = 0 and total = 0
3) while(count<n):
4) Read the amount of milk from each of the n farms, litres
5) count = count + 1
6) total = total + litres
END

Flow Chart:




Q5) Arjun, amith and sharma are friends. Given their marks in Maths, design an algorithm and draw a flowchart to find minimum of their marks.

Input:
Read marks of Arjun in maths
Read marks of Amit in maths
Read marks of Sharma in maths

Code:
m1=int(input())
m2=int(input())
m3=int(input())
if(m1>=0 and m1<=100 and m2>=0 and m2<=100 and m3>=0 and m3<=100):
min=m1
if(m2<min):
min=m2
if(m3<min):
min=m3
print(min)
else:
print('Invalid input')

Processing:

if(m1>=0 and m1<=100 and m2>=0 and m2<=100 and m3>=0 and m3<=100):
min=m1
if(m2<min):
min=m2
if(m3<min):
min=m3
print(min)
else:
print('Invalid input')

Output:
Print the name of student who scored minimum marks in maths
Print the minimum marks in maths

Pseudo Code:
START
1) Read marks of Arjun in maths
2) Read marks of Amit in maths
3) Read marks of Sharma in maths
4) if(m1>=0 and m1<=100 and m2>=0 and m2<=100 and m3>=0 and m3<=100), continue
5) let min=m1
6) if(m2<min), update min=m2
7) if(m3<min), update min=m3
8) Print min
END

Flow Chart:


Comments

  1. These codes are 100% working in our view. If you find any errors by using the above codes.please comment in comment section

    ReplyDelete

Post a Comment

Popular posts from this blog

PPS2

PRACTICE PROBLEMS 2 FALL 18 Q1)  A city has a dam of capacity 'x' litres, water comes to the dam from 'n' places. Given the value of 'n' and the quantity of water (in litres and millilitres) that comes from 'n' places. Write an algorithm and the corresponding Python code to determine the total amount of water in the dam. Assume that the total quantity of water in the dam, will always be less than the capacity of the dam. For example, if there are three places from which water comes to the dam and the water from place 1 is 2 litres 500 ml, water from second place is 3 litres 400 ml and water from third place is 1 litre 700 ml, then the total quantity of water in dam will be 7 litres 600 ml. Code: n=int(input()) lit=0 ml=0 for i in range(n):  lit=lit+int(input())  ml=ml+int(input()) print(lit+(ml//1000)) print(ml%1000) Input: 'n' number of litres and ml of water from each of the 'n' places Processing: for i in range(n):...