Tutte le sfide
Facile 4 risolte 66.7% di accettazione

Ticket Price by Age

Choose a cinema ticket price from the visitor's age.

Cosa imparerai

  • Choose a value from age ranges
  • Write non-overlapping conditions
  • Test boundary ages

Problema

Mostra traduzione

A cinema charges by age: children under 3 are free, ages 3–12 pay 5, ages 13–64 pay 12, and 65 or older pay 7.

Implement ticket_price(age).

Input

age: The visitor's age in years.

Output

Return the ticket price.

Vincoli

0 ≤ age ≤ 120

Esempi

Esempio 1
Input:
age = 10

Output atteso:
expected = 5
Input:
long long age = 10;

Output atteso:
long long expected = 5;
Input:
long age = 10;

Output atteso:
long expected = 5;

Spiegazione

10 is between 3 and 12, so the price is 5.

Esempio 2
Input:
age = 70

Output atteso:
expected = 7
Input:
long long age = 70;

Output atteso:
long long expected = 7;
Input:
long age = 70;

Output atteso:
long expected = 7;

Spiegazione

70 is 65 or older, so the senior price of 7 applies.

Come affrontarlo

Prova prima da solo, poi apri un suggerimento alla volta.

Suggerimento 1

The price depends on which age band the visitor falls into.

Suggerimento 2

Check the youngest and oldest special cases before the middle ranges.

Suggerimento 3

Pay attention to the exact endpoints so ages 3, 13, and 65 get the correct prices.

Complessità attesa

O(1) time, O(1) extra space

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

La migliore soluzione superata di ogni programmatore. Le più veloci, leggere e meglio valutate stanno in alto.

# Programmatore Linguaggio Tempo Memoria Voto dell'IA Soluzione
1 RCRiccardo Corti Python 1,212 ms - 4/5 Vedi il codice
2 LMLaura Mahlow Python 1,214 ms - 5/5 Vedi il codice
3 ДЗДавид Зайдулин Python 1,224 ms - 4/5 Vedi il codice
4 PKPornchai Kaewkrabil Go 1,510 ms - 4/5 Vedi il codice

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 4 soluzioni complete sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le revisioni dell'IA. Accedi e risolvi la sfida per partecipare alla discussione.