Advertisement
Tandy234

Untitled

Feb 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1. #Author - Andrei Pascu
  2. #Date - 04/02/16
  3.  
  4. #The cost variable is globalised and defined so that it can be used in other functions.
  5. global cost
  6. cost = 0
  7.  
  8. def welcomemessage():
  9. #This function prints a welcome message whenever called
  10. print('Welcome! \n Please all the details below to calculate your total costs.\n')
  11.  
  12. def exitmessage():
  13. #This program prints a welcome message and closes the program whenever called
  14. print('Your estimate has been calculated finished, goodbye! ')
  15. #Here the SystemExit function is raised so that the whole system module does not have to be imported. Once the function is imported and executed the program is stopped to stop the loop of asking if the user wants to start again,
  16. #but only if he answers no to the question
  17. raise SystemExit
  18.  
  19. def startmain():
  20. #This function starts the main sequence of the program, allowing the user to see the welcome message, and then be asked all the details to calculate the total
  21. welcomemessage()
  22. takedetails()
  23.  
  24. def takedetails():
  25. #This function is one of the main parts of the program, it asks the user for all the details in order to calculate the total in the second function of the program
  26.  
  27. #Here all of the variables necessary to make to function work and take in the user's details are made global
  28. global area, height, width, wallpremove
  29. #Here the variables required to make the code function correctly are defined
  30. roomnum = 0
  31. wallnum = 0
  32. width = 0
  33. height = 0
  34. area = 0
  35. cost = 0
  36. wallpremove = 0
  37. #Below the user is asked for the following details: costumer number, date of estimate, Number of rooms that require painting, how many rooms need wallpaper removal.
  38. costumerNo=input('Please enter your customer number ')
  39. estdate=input('What is the date of your estimate? (DD/MM/YY) ')
  40. roomno = int(input('How many rooms require painting? '))
  41. wallpremove=int(input('For how many of your rooms would you like to have the wallpaper removed? '))
  42. #Here the user is asked if he wants to add another room
  43. response=input('Would you like to add another room? (Y or N) ')
  44. #If the response is 'N' , the user is asked to input the information for the rooms entered above.
  45. if response == 'N':
  46. #The user is asked the name, number of walls, measurements (height, width) here for the amount of rooms he entered.
  47. for i in range(roomno):
  48.  
  49. #The roomnum variable is used to display the room number so that the user knows how many rooms he's entered so far, this variable increments in +1 so that for the amount of rooms entered,
  50. #each time the loop starts again 1 is added.
  51. roomnum = roomnum + 1
  52. #The name of the room is asked here, and then the message telling the user to enter the measurements for the room.
  53. print('Please enter the name of Room',roomnum,': ')
  54. roomname=str(input('Name:'))
  55. wallno=int(input('Please enter the number of walls in this room '))
  56. print('Please enter measurements for room ',roomnum)
  57. #Here the variable wallnum is defined so that when the loop moves onto the next room, the wall number indicator is reset.
  58. wallnum = 0
  59.  
  60. for i in range(wallno):
  61. #The the amount of walls, firstly, the height and width variables are reset so that when the loop moves onto the next room, the height and width does not get overwritten by the previous room dimensions, and so the area
  62. #can be calculated correctly.
  63. height = 0
  64. width = 0
  65. #Much like in the first loop, another incrementing variable is defined here to indicate which wall number the user is on.
  66. wallnum = wallnum + 1
  67. #Here the wall height and width are asked to be entered.
  68. print('Please enter the measurements for wall ',wallnum,)
  69. height= float(input('Enter height of the wall ')) + height
  70. width=float(input('Enter the width of the wall ')) + width
  71. #The area is worked out by multiplying the height and the width, and adding it to the area of previous rooms.
  72. area= area + (height*width)
  73. #When the loop is finished here, the function costcalucation is initiated and the user is asked which type of worker is wanted (Apprentice or Fully Qualified), the total cost is displayed, and then the user is asked if he wants
  74. #to start over again.
  75. costcalculation()
  76.  
  77. while response == 'Y':
  78.  
  79. roomadd=int(input('How many rooms would you like to add? '))
  80. #The extra number of rooms are added to the initial number of rooms here.
  81. roomno=roomno+roomadd
  82. for i in range(roomno):
  83. #The roomnum variable is used to display the room number so that the user knows how many rooms he's entered so far, this variable increments in +1 so that for the amount of rooms entered,
  84. #each time the loop starts again 1 is added.
  85. roomnum = roomnum + 1
  86. #The name of the room is asked here, and then the message telling the user to enter the measurements for the room.
  87. print('Please enter the name of Room',roomnum,': ')
  88. roomname=str(input('Name: '))
  89. wallno=int(input('Please enter the number of walls in this room '))
  90. print('Please enter measurements for room ',roomnum)
  91. #Here the variable wallnum is defined so that when the loop moves onto the next room, the wall number indicator is reset.
  92. wallnum = 0
  93.  
  94. for i in range(wallno):
  95. #The the amount of walls, firstly, the height and width variables are reset so that when the loop moves onto the next room, the height and width does not get overwritten by the previous room dimensions, and so the area
  96. #can be calculated correctly.
  97. height = 0
  98. width = 0
  99. #Much like in the first loop, another incrementing variable is defined here to indicate which wall number the user is on.
  100. wallnum = wallnum + 1
  101. #Here the wall height and width are asked to be entered.
  102. print('Please enter the measurements for wall ',wallnum,)
  103. height= float(input('Enter height of the wall ')) + height
  104. width=float(input('Enter the width of the wall ')) + width
  105. area= area +(height*width)
  106. #When the loop ends and the user has entered all the details, he is asked if he wants to enter another room for the final time before going onto the cost calculations.
  107. response2=input('Would you like to add another room? (Y or N) ')
  108. #If the user enters yes to the questions below, the loop starts again
  109. if response2=='Y':
  110. #When the user enters yes, the roomno variable is reset so that the user can enter how many rooms he wants to add, and not have to re-enter the details of the previous rooms again.
  111. roomno= 0
  112. #When the user enters no, the costcalculation variable is initiated and the user is asked which type of worker is wanted (Apprentice or Fully Qualified), the total cost is displayed, and then the user is asked if he wants
  113. #to start over again.
  114. if response2=='N':
  115. costcalculation()
  116.  
  117. def costcalculation():
  118. #The costcalucation function asks the user for the type of worker they want, and then asks them if they want to start over again until they say no. If they say yes, all the variables that are needed to make the program function
  119. #correctly are reset so that nothing is overwritten or added onto, and so the correct total cost can be displayed everytime it resets. If they answer no, the exitmessage function is initiated where an exit message is printed out
  120. #and the program is stopped.
  121. #The below variables are made global so that they can be used again in other functions as well as this one.
  122. global wallpremove
  123. global area
  124. #Here the user is asked what type of worker is wanted for the job so that the cost can be added on.
  125. workertype=input('What type of worker would you like? AP for Apprentice, or FQ for fully qualified. ')
  126. #Here the total cost is calculated
  127. if workertype == 'AP':
  128. #If the user enters AP for Apprentice, the cost is increased by £100, and the total cost is worked out by adding the cost by the total cost of the wallpaper (number of rooms to have wallpaper removed multiplied by £70), and adds
  129. #the cost of of the paint by multiplying the area calculated by the width and height of each wall before in the first takedetails function. The total of this is then multiplied by 1.2 for the VAT value of 20%.
  130. cost = (cost + 100)
  131. cost = (cost +(wallpremove * 70)+(area*15)) * 1.2
  132.  
  133. else:
  134. #If the user enters FQ for Fully Qualified, the cost is increased by £100, and the total cost is worked out by adding the cost by the total cost of the wallpaper (number of rooms to have wallpaper removed multiplied by £70), and adds
  135. #the cost of of the paint by multiplying the area calculated by the width and height of each wall before in the first takedetails function. The total of this is then multiplied by 1.2 for the VAT value of 20%.
  136. cost = (cost + 250)
  137. cost = (cost +(wallpremove * 70)+(area*15)) * 1.2
  138. #Once the cost has been calculated, it is then displayed.
  139. print('Your estimated cost is: £',cost,)
  140. #After the cost has been displayed, the user is asked if he/she would like to restart and re-enter all the details
  141. restart=input('Would you like to re-enter details and calculate another estimate? (Y or N)')
  142. #If the user enters no to the question above, the exitmessage function is initiated which displays and exit message and uses a specific function from the system module to stop the program.
  143. if restart == 'N':
  144. exitmessage()
  145.  
  146. while restart == 'Y':
  147. #This loop makes the user start the program again until he/she says no to the question at the end, if he/she says no, the exitmessage function is initiated to display an exit message and stop the program.
  148. #Here all of the variables are reset so that they are not overwritten or added onto the previous inputs before the restart.
  149. roomnum = 0
  150. wallnum = 0
  151. width = 0
  152. height = 0
  153. area = 0
  154. cost = 0
  155. wallpremove = 0
  156. #The startmain function initiates the welcomemessage and takedetails function so that the user can start again and re-enter all of the details.
  157. startmain()
  158.  
  159. if restart == 'N':
  160. #If the user enters no to the previous, the exitmessage function is initiated which displays and exit message and uses a specific function from the system module to stop the program.
  161. exitmessage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement