Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. Railcard exercise - October half term test
  2.  
  3. Student name: Max Tiger Deans Dillon
  4. Student group: Year 1B 17-19 EX
  5. Total: 32 out of 50
  6.  
  7. Brief: 2
  8. Flowchart: 3
  9. Pseudocode: 4
  10. Link to Python program: 5
  11. Code listing: 5
  12. Test log: 6
  13.  
  14.  
  15. Brief:
  16. Write a program to calculate the cost of a train ticket. There are two destinations (the train is starting from Leamington Spa):
  17.  
  18.  
  19. Destination
  20. Ticket price
  21. London
  22. £60.00
  23. Birmingham
  24. £15.00
  25.  
  26. There are four different ticket price options:
  27.  
  28. Category
  29. Discount
  30. Child (below 15)
  31. 50% discount
  32. 16 - 25 railcard
  33. ⅓ off original price
  34. Senior railcard
  35. 25% discount
  36. No railcard
  37. No discount
  38.  
  39. The program needs to ask the user where they are travelling to, and what type of ticket they will be purchasing
  40. The program should check for invalid input
  41. The program should print out the destination and the price of the ticket
  42. Stretch and challenge task: If you have time, make the program loop and keep asking for a ticket choice until the user asks to exit the program.
  43.  
  44. Flowchart:
  45.  
  46. (7 out of 10 marks)
  47. Need to join the arrows to the next shape they go to. No provision for re-entry if ticket type or destination entered incorrectly.
  48. Pseudocode:
  49. stations = ["London", "london", "Birmingham", "birmingham"]
  50. x = 0
  51. price = 0
  52. def cardtype():
  53. global price
  54. while True :
  55. cardtype = (input("""1 = child
  56. 2 = 16-25 railcard
  57. 3 = senior railcard
  58. 4 = no card
  59. Enter ticket type: """))
  60. if cardtype == "1":
  61. price = price / 2
  62. break
  63. if cardtype == "2":
  64. price = price * 2/3
  65. break
  66. if cardtype == "3":
  67. price = price * .25
  68. break
  69. if cardtype == "4":
  70. break
  71. else:
  72. print ("Not valid input")
  73. while x == 0:
  74. dest = str(input("What is your destination"))
  75. if dest in stations:
  76. x = 1
  77. if dest.upper() == "LONDON":
  78. price = 60
  79. if dest.upper() == "BIRMINGHAM":
  80. price = 15
  81. else:
  82. print ("This station is not valid")
  83. cardtype()
  84. print ("You are going to ",dest)
  85. print ("Your price is £",price)
  86.  
  87. (5 out of 10 marks)
  88. Link to Python program:
  89.  
  90. Code listing:
  91.  
  92. stations = ["London", "london", "Birmingham", "birmingham"]
  93. x = 0
  94. price = 0
  95. def cardtype():
  96. global price
  97. while True :
  98. cardtype = (input("""1 = child
  99. 2 = 16-25 railcard
  100. 3 = senior railcard
  101. 4 = no card
  102. Enter ticket type: """))
  103. if cardtype == "1":
  104. price = price / 2
  105. break
  106. if cardtype == "2":
  107. price = price * 2/3
  108. break
  109. if cardtype == "3":
  110. price = price * .25
  111. break
  112. if cardtype == "4":
  113. break
  114. else:
  115. print ("Not valid input")
  116. while x == 0:
  117. dest = str(input("What is your destination"))
  118. if dest in stations:
  119. x = 1
  120. if dest.upper() == "LONDON":
  121. price = 60
  122. if dest.upper() == "BIRMINGHAM":
  123. price = 15
  124. else:
  125. print ("This station is not valid")
  126. cardtype()
  127. print ("You are going to ",dest)
  128. print ("Your price is £",price)
  129.  
  130.  
  131. (15 out of 20 marks)
  132.  
  133. Test log:
  134. (5 out of 10 marks)
  135.  
  136. Test
  137. Expected result
  138. Actual result
  139. London
  140. London is chosen as the destination
  141. London is chosen as the destination
  142. 1
  143. £30
  144. Price is £30
  145. 2
  146. £40
  147. Price is £40
  148. 3
  149. £55
  150. Price is £55
  151. 4
  152. £60
  153. Price is £60
  154. Birmingham
  155.  
  156.  
  157. Birmingham is the destination
  158. 1
  159. £7.5
  160. Price is £7.5
  161. 2
  162. £10
  163. Price is £10
  164. 3
  165. £11.25
  166. Price is £11.25
  167. 4
  168. £15
  169. Price is £15
  170. Brighton
  171. Print not valid and ask again.
  172. Prints not valid
  173. 212345
  174. Print not valid and ask again.
  175. Prints not valid
  176. 12
  177. Print not valid and ask again.
  178. Prints not valid
  179. £\54£"ws
  180. Print not valid and ask again.
  181. Prints not valid
  182. 1 2 3
  183. Print not valid and ask again.
  184. Prints not valid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement