Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Haaste: Pääsy- ja Lippuetujen Moottori | Ristikkäiset Tyyppivuorovaikutukset
Tietotyypit Pythonissa

bookHaaste: Pääsy- ja Lippuetujen Moottori

Tehtävä

Swipe to start coding

Use only variables, operators, and the tools we covered — strip, casefold, int, slicing, comparisons, and logical operators — to complete each expression.

Compute:

  1. age – convert age_str to an integer.
  2. has_id – normalize has_id_str and check if it equals "yes" (Boolean).
  3. Split ticket_code into tier, seat_number_str, and zone by slicing fixed positions.
  4. seat_number – convert seat_number_str to an integer.
  5. Rules:
    • is_adult: age >= adult_age.
    • can_enter: must have ID and be adult.
    • vip_perk: tier == "VIP".
    • member_fastlane: user is a member and can enter.
    • seat_ok: seat number between 1 and max_seat_number (inclusive).
    • entry_granted: can enter and seat is OK.
  6. Build summary using an f-string: "{tier}-{seat_number_str}-{zone} | age={age} | enter={entry_granted} | vip={vip_perk} | fastlane={member_fastlane}".

Ratkaisu

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 4. Luku 4
single

single

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

close

bookHaaste: Pääsy- ja Lippuetujen Moottori

Pyyhkäise näyttääksesi valikon

Tehtävä

Swipe to start coding

Use only variables, operators, and the tools we covered — strip, casefold, int, slicing, comparisons, and logical operators — to complete each expression.

Compute:

  1. age – convert age_str to an integer.
  2. has_id – normalize has_id_str and check if it equals "yes" (Boolean).
  3. Split ticket_code into tier, seat_number_str, and zone by slicing fixed positions.
  4. seat_number – convert seat_number_str to an integer.
  5. Rules:
    • is_adult: age >= adult_age.
    • can_enter: must have ID and be adult.
    • vip_perk: tier == "VIP".
    • member_fastlane: user is a member and can enter.
    • seat_ok: seat number between 1 and max_seat_number (inclusive).
    • entry_granted: can enter and seat is OK.
  6. Build summary using an f-string: "{tier}-{seat_number_str}-{zone} | age={age} | enter={entry_granted} | vip={vip_perk} | fastlane={member_fastlane}".

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 4. Luku 4
single

single

some-alt