I'm building a CLI to help users follow complex guidance answering one question at a…
- User
I'm building a CLI to help users follow complex guidance answering one question at a time. Input is taken via
def""" Await user input with the specified prompt, then cast it to `type` and return. supported types are: bool, str, float and union of literals, e.g. "male" | "female" """Output of each
askshould be assigned to a clearly named variable. Return as soon as result can be determined.codedef can\_purchase\_alcohol\_in\_uk() -> bool: percieved\_age = ask("How old does the person seem to be?", float) if percieved\_age > 25: return True actual\_age= typer.prompt("Age according to photographic ID?", float) return age >= 18Collapse if-else conditions into one line if possible, for example:
codeif x==1: return True else: return Falserewrite as:
codereturn x==1Do not generate any additional text.
My new CLI will be about Cyprus tax residency. The rules are: """ As of 2017, an individual is a tax resident of Cyprus if one satisfies either the '183-day rule' or the '60-day rule' for the tax year. For earlier tax years only, the '183-day rule' is relevant for determining Cyprus tax residency. The '183-day rule' for Cyprus tax residency is satisfied for individuals who spend more than 183 days in any one calendar year in Cyprus, without any further additional conditions/criteria being relevant. The '60-day rule' for Cyprus tax residency is satisfied for individuals who, cumulatively, in the relevant tax year: do not reside in any other single state for a period exceeding 183 days in aggregate are not considered tax resident by any other state reside in Cyprus for at least 60 days, and have other defined Cyprus ties. To satisfy the fourth criteria, the individual must carry out any business in Cyprus and/or be employed in Cyprus and/or hold an office (director) of a company tax resident in Cyprus at any time in the tax year, provided that such is not terminated during the tax year. Further, the individual must maintain in the tax year a permanent residential property in Cyprus that is either owned or rented by the individual. """ Example code of the CLI is:
- Assistantcode
def is_cyprus_tax_resident(tax_year: int) -> bool: if tax_year < 2017: days_in_cyprus = ask("How many days were you in Cyprus in the tax year?", float) return days_in_cyprus > 183 else: days_in_cyprus = ask("How many days were you in Cyprus in the tax year?", float) days_in_other_state = ask("How many days were you in other state in the tax year?", float) resident_other_state = ask("Are you a tax resident of any other state?", bool) business_in_cyprus = ask("Did you carry out any business in Cyprus in the tax year?", bool) employed_in_cyprus = ask("Were you employed in Cyprus in the tax year?", bool) office_in_cyprus_company = ask("Did you hold an office of a company tax resident in Cyprus in the tax year?", bool) office_terminated = ask("Was your office terminated during the tax year?", bool) property_in_cyprus = ask("Did you maintain a permanent residential property in Cyprus in the tax year?", bool) return (days_in_cyprus >= 60 and days_in_other_state <= 183 and not resident_other_state and (business_in_cyprus or employed_in_cyprus or (office_in_cyprus_company and not office_terminated)) and property_in_cyprus)