Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

python double check if wants to execute funtion

while True:
    try:
        age = int(input("Please enter your age: "))
    except ValueError:
        print("Sorry, I didn't understand that.")
        continue

    if age < 0:
        print("Sorry, your response must not be negative.")
        continue
    else:
        #age was successfully parsed, and we're happy with its value.
        #we're ready to exit the loop.
        break
if age >= 18: 
    print("You are able to vote in the United States!")
else:
    print("You are not able to vote in the United States.")
Comment

python double check if wants to execute funtion

while True:
    data = input("Please enter a loud message (must be all caps): ")
    if not data.isupper():
        print("Sorry, your response was not loud enough.")
        continue
    else:
        #we're happy with the value given.
        #we're ready to exit the loop.
        break

while True:
    data = input("Pick an answer from A to D:")
    if data.lower() not in ('a', 'b', 'c', 'd'):
        print("Not an appropriate choice.")
    else:
        break
Comment

python double check if wants to execute funtion

def get_non_negative_int(prompt):
    while True:
        try:
            value = int(input(prompt))
        except ValueError:
            print("Sorry, I didn't understand that.")
            continue

        if value < 0:
            print("Sorry, your response must not be negative.")
            continue
        else:
            break
    return value

age = get_non_negative_int("Please enter your age: ")
kids = get_non_negative_int("Please enter the number of children you have: ")
salary = get_non_negative_int("Please enter your yearly earnings, in dollars: ")
Comment

python double check if wants to execute funtion

def sanitised_input(prompt, type_=None, min_=None, max_=None, range_=None):
    if min_ is not None and max_ is not None and max_ < min_:
        raise ValueError("min_ must be less than or equal to max_.")
    while True:
        ui = input(prompt)
        if type_ is not None:
            try:
                ui = type_(ui)
            except ValueError:
                print("Input type must be {0}.".format(type_.__name__))
                continue
        if max_ is not None and ui > max_:
            print("Input must be less than or equal to {0}.".format(max_))
        elif min_ is not None and ui < min_:
            print("Input must be greater than or equal to {0}.".format(min_))
        elif range_ is not None and ui not in range_:
            if isinstance(range_, range):
                template = "Input must be between {0.start} and {0.stop}."
                print(template.format(range_))
            else:
                template = "Input must be {0}."
                if len(range_) == 1:
                    print(template.format(*range_))
                else:
                    expected = " or ".join((
                        ", ".join(str(x) for x in range_[:-1]),
                        str(range_[-1])
                    ))
                    print(template.format(expected))
        else:
            return ui
Comment

python double check if wants to execute funtion

age = sanitised_input("Enter your age: ", int, 1, 101)
answer = sanitised_input("Enter your answer: ", str.lower, range_=('a', 'b', 'c', 'd'))
Comment

python double check if wants to execute funtion

data = input("Please enter a loud message (must be all caps): ")
while not data.isupper():
    print("Sorry, your response was not loud enough.")
    data = input("Please enter a loud message (must be all caps): ")
Comment

PREVIOUS NEXT
Code Example
Typescript :: managed code array too few arguments for class template 
Typescript :: kotlin version that is used for building with gradle 
Typescript :: Using TypeScript generic with `...rest` operator 
Typescript :: react input onchange typescript 
Typescript :: google sheets script save A RANGE to csv 
Typescript :: studying for a sceince test 
Typescript :: typescript encode url 
Typescript :: create a 4x2 integer array and print its attributes 
Typescript :: mongodb node findone how to handle no results using promises 
Typescript :: when we dont have to show data of child but change in child should be displayed in parent automatically 
Typescript :: sequelize puts an s end of name 
Typescript :: whats the extension of a markup language 
Typescript :: testing without requirements 
Typescript :: my controller is not recognized and it actually exists why is this happening 
Typescript :: how to write elements of a list as a string with a comma between elements in python 
Typescript :: what do you expect from us 
Typescript :: language 
Typescript :: types of pacemaker 
Typescript :: how to use array pop in typescript 
Typescript :: 5 lakes of north america 
Typescript :: why are lower case alphabets more preffered in html 
Typescript :: delete in typescript with a toaster notification 
Typescript :: TypeScript interface for object with arbitrary numeric property names? 
Typescript :: how to add lists haskell 
Typescript :: how to convert js to ts 
Typescript :: check jasmine version 
Typescript :: exits adn copy file in java 
Typescript :: post data 
Typescript :: routerextensions nativescript 7 import 
Typescript :: FIFA 21 esports temas 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =