Tuesday, October 19, 2021

Python Assignments and Answers

Question 1)
A canteen of a school sells 10 different types of foods. These food types are placed in a shelf. Students can select foods while walking alongside the shelf and keep them on a tray. These trays are available at the entrance of the canteen. A student, after selecting the food, should proceed to the cashier with the food tray for the payment.
You are asked to develop a computer program to calculate the payment due for a food tray. For this purpose, each food type is given a unique integer from 1 to 10.
The integer value assigned for each food type and its unit price is shown in the following table.

Food type - Price (Rs.)
1 - 10.00
2 - 12.00
3 - 15.00
4 - 10.00
5 - 25.00
6 - 45.00
7 - 50.00
8 - 25.00
9 - 10.00
10 - 12.00

a) State all the inputs required for the computer program and its expected output.
b) Draw a flowchart to represent the algorithm required to compute the payment due for a food tray.
c) transform the above flowchart into a Python program.


a)
Input
Need to input Food type but price of the food can be retrieved from the list
Need to input number of items (Qty) Finish the calculation need to have a key to end, -1 is used to end repetition.
Output
print the Payment due (Total amount to be paid to the bill)
b)

Flowchart and Python Program
 
c) Python program is given below

price=[10.00,12.00,15.00,10.00,25.00,45.00,50.00,25.00,10.00,12.00]
mytot=0
myitem=0
while myitem >-1 :
     myitem=int(input('Enter a item Number?'))
     if myitem>=0 and myitem<=9:
          myitem=int(myitem-1)
          myprice=price[myitem]
          myqty=float(input('Enter a item Qty'))
          mytot=mytot+float(myprice*myqty)
print('Your Total due is=',mytot)


Question 2)
What is the output of the python program given below

 
Program

j=10
y=4
if j < y or j!=4:
     j-=y
     print (j)
else:
     y*=j
     print (y)


Output
6


No comments:

Post a Comment