21.8k views
18 votes
The visitor's age is stored in the variable age, the day of the week is stored in a variable day, and the price in dollars is stored in the variable price. Which piece of code will correctly decide the price for each ticket.

User Sps
by
3.0k points

1 Answer

8 votes

Answer:

If a museum charges different prices based on the day of the week and age of the visitor. The pricing rules are shown below.

- On Tuesday and Thursday children 10 and under get in free ($ 0).

- For all other days and ages the cost is ten dollars ($ 10).

The code in python is;

if (day == 'Tuesday' or day == 'Thursday') and age <= 10:

price = 0

else:

price = 10

Step-by-step explanation:

The logic of the algorithm suggests that that the conditional if-statement assigns zero to the price variable if the day variable is either Tuesday or Thursday and the child's age is 10 or below but assigns 10 to the price variable if the condition is not met.

User Artiebits
by
3.6k points