livepython.net

155. Python Program to Make a Ticket Machine with finally

Mediumelse and finally

Overview

Use all four parts of a try statement: try, except, else and finally.

Problem Statement

A ticket costs 50. Read the number of tickets (a whole number) and print the total, like this for 3:

Total: 150

  • If the input is not a whole number, print Please type a whole number
  • If the number is less than 1, print Buy at least one ticket

In every case, the last line is:

Thank you for visiting

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value. Example:

3

Output

The output for that example:

Total: 150
Thank you for visiting

The tests try 4 different inputs.

Learn this firstChapter 17 · Python try, except, else and finally Explained
solution.py
# write your code here

EXPECTED OUTPUT

1Total: 150
2Thank you for visiting

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.