Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Railcard exercise - October half term test
- Student name: Max Tiger Deans Dillon
- Student group: Year 1B 17-19 EX
- Total: 32 out of 50
- Brief: 2
- Flowchart: 3
- Pseudocode: 4
- Link to Python program: 5
- Code listing: 5
- Test log: 6
- Brief:
- Write a program to calculate the cost of a train ticket. There are two destinations (the train is starting from Leamington Spa):
- Destination
- Ticket price
- London
- £60.00
- Birmingham
- £15.00
- There are four different ticket price options:
- Category
- Discount
- Child (below 15)
- 50% discount
- 16 - 25 railcard
- ⅓ off original price
- Senior railcard
- 25% discount
- No railcard
- No discount
- The program needs to ask the user where they are travelling to, and what type of ticket they will be purchasing
- The program should check for invalid input
- The program should print out the destination and the price of the ticket
- 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.
- Flowchart:
- (7 out of 10 marks)
- Need to join the arrows to the next shape they go to. No provision for re-entry if ticket type or destination entered incorrectly.
- Pseudocode:
- stations = ["London", "london", "Birmingham", "birmingham"]
- x = 0
- price = 0
- def cardtype():
- global price
- while True :
- cardtype = (input("""1 = child
- 2 = 16-25 railcard
- 3 = senior railcard
- 4 = no card
- Enter ticket type: """))
- if cardtype == "1":
- price = price / 2
- break
- if cardtype == "2":
- price = price * 2/3
- break
- if cardtype == "3":
- price = price * .25
- break
- if cardtype == "4":
- break
- else:
- print ("Not valid input")
- while x == 0:
- dest = str(input("What is your destination"))
- if dest in stations:
- x = 1
- if dest.upper() == "LONDON":
- price = 60
- if dest.upper() == "BIRMINGHAM":
- price = 15
- else:
- print ("This station is not valid")
- cardtype()
- print ("You are going to ",dest)
- print ("Your price is £",price)
- (5 out of 10 marks)
- Link to Python program:
- Code listing:
- stations = ["London", "london", "Birmingham", "birmingham"]
- x = 0
- price = 0
- def cardtype():
- global price
- while True :
- cardtype = (input("""1 = child
- 2 = 16-25 railcard
- 3 = senior railcard
- 4 = no card
- Enter ticket type: """))
- if cardtype == "1":
- price = price / 2
- break
- if cardtype == "2":
- price = price * 2/3
- break
- if cardtype == "3":
- price = price * .25
- break
- if cardtype == "4":
- break
- else:
- print ("Not valid input")
- while x == 0:
- dest = str(input("What is your destination"))
- if dest in stations:
- x = 1
- if dest.upper() == "LONDON":
- price = 60
- if dest.upper() == "BIRMINGHAM":
- price = 15
- else:
- print ("This station is not valid")
- cardtype()
- print ("You are going to ",dest)
- print ("Your price is £",price)
- (15 out of 20 marks)
- Test log:
- (5 out of 10 marks)
- Test
- Expected result
- Actual result
- London
- London is chosen as the destination
- London is chosen as the destination
- 1
- £30
- Price is £30
- 2
- £40
- Price is £40
- 3
- £55
- Price is £55
- 4
- £60
- Price is £60
- Birmingham
- Birmingham is the destination
- 1
- £7.5
- Price is £7.5
- 2
- £10
- Price is £10
- 3
- £11.25
- Price is £11.25
- 4
- £15
- Price is £15
- Brighton
- Print not valid and ask again.
- Prints not valid
- 212345
- Print not valid and ask again.
- Prints not valid
- 12
- Print not valid and ask again.
- Prints not valid
- £\54£"ws
- Print not valid and ask again.
- Prints not valid
- 1 2 3
- Print not valid and ask again.
- Prints not valid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement