示例#1
0
def get_user_input():
    user_input = None

    # Checks to see if the integer is within the desired range or if it is a string.
    # If any of these inputs are not correct, it will continue to ask the question until a correct input is given.
    while not verify.valid_input(
            user_input, against_range=True, range_low=0, range_high=100):
        user_input = input(
            "What score did you get on your test? (Respond in whole number from 0-100) "
        )

    # Returns the input as an integer instead of a string.
    return int(user_input)
示例#2
0
def print_specific_face():

    # Pre-specified inputs
    emoticon_input = None
    user_emoticon = ""

    # Prints the Eyes menu
    print("-----------------------")
    print("List of Eyes")
    print("0 - :")
    print("1 - ;")
    print("2 - 8")
    print("3 - =")
    print("4 - Random Eyes")

    # Checks whether the number is numeric or within the specified range, and
    # asking continuously until given a proper input to exit the loop.
    # Ranges are -1 and 5 to inclujde 0 and 4 within the check
    while not verify.valid_input(
            emoticon_input, against_range=True, range_low=-1, range_high=5):
        emoticon_input = input(
            "Please select a number based on what eyes you want (0-4): ")

    # Sets user_emoticon to the choice of eyes
    if int(emoticon_input) == 4:
        user_emoticon = random.choice(eyes)
    else:
        user_emoticon = eyes[int(emoticon_input)]

    # Prints the Nose Menu
    print("-----------------------")
    print("List of Nose")
    print("0 - ^")
    print("1 - O")
    print("2 - *")
    print("3 - Random Nose")

    # Resets emoticon_input to continue checking inputs.
    emoticon_input = None

    # Checks whether the number is numeric or within the specified range, and
    # asking continuously until given a proper input to exit the loop.
    # Ranges are -1 and 4 to inclujde 0 and 3 within the check
    while not verify.valid_input(
            emoticon_input, against_range=True, range_low=-1, range_high=4):
        emoticon_input = input(
            "Please select a number based on what nose you want (0-3): ")

    # Appends user_emoticon with the choice of nose.
    if int(emoticon_input) == 3:
        user_emoticon += random.choice(noses)
    else:
        user_emoticon += noses[int(emoticon_input)]

    # Prints the Mouths menu
    print("-----------------------")
    print("List of Mouths")
    print("0 - )")
    print("1 - (")
    print("2 - [")
    print("3 - ]")
    print("4 - Random Mouth")

    # Resets emoticon_input to continue checking inputs.
    emoticon_input = None

    # Checks whether the input is numeric or within the specified range, and
    # asking continuously until given a proper input to exit the loop.
    # Ranges are -1 and 5 to inclujde 0 and 4 within the check
    while not verify.valid_input(
            emoticon_input, against_range=True, range_low=-1, range_high=5):
        emoticon_input = input(
            "Please select a number based on what mouth you want (0-4): ")

    # Appends user_emoticon with the choice of mouth.
    if int(emoticon_input) == 4:
        user_emoticon += random.choice(mouths)
    else:
        user_emoticon += mouths[int(emoticon_input)]

    # Prints the emoticon
    print(user_emoticon)
示例#3
0
    if int(emoticon_input) == 4:
        user_emoticon += random.choice(mouths)
    else:
        user_emoticon += mouths[int(emoticon_input)]

    # Prints the emoticon
    print(user_emoticon)


user_input = None
# Prints the opening message
print_random_face_message()

# Checks whether the input is numeric and if the input is a positive integer,
# while asking continuously until given a proper input to exit the loop.
while not verify.valid_input(user_input, is_positive=True):
    user_input = str(
        round(float(input("How many faces would you like to print? "))))

# Prints the number of specified faces the user wished to see.
print_random_faces_input(int(user_input))
user_input = None
# Checks if the input is "Y" or "N" in order to continue. Both responses will
# exit the loop.
while not verify.valid_input(
        user_input, correct_inputs, against_list=True, against_string=True):
    user_input = input("Do you want another emoticon face? (Yes/No) ")

    # If the user input is "Y", it will print a random face.
    if user_input == "Yes":
        print(return_random_face())
示例#4
0
            f"Eventually they subside and become {random.choice(adjective)} giants or perhaps black {random.choice(plural_noun)}."
        )
        print(
            f"Our own planet, which we call {first_name}, circles around our {random.choice(adjective)} sun {number} times every year. There are eight other planets in our solar system."
        )
        print(
            f"They are named {another_first_name[0]}, {another_first_name[1]}, {another_first_name[2]}, {another_first_name[3]}, {another_first_name[4]}, {another_first_name[5]}, Jupiter, and Mars."
        )
        print(
            f"Scientists who study these planets are called {random.choice(plural_noun)}."
        )
        # Resets print words so that it can inquire if the player wants to print the story again after printing.
        print_words = None
        # Checks to see if the user wants to print the story again, causing some words to change due to random.choice(), "Yes" continues the loop, "No" exits the loop.
        while not verify.valid_input(
                print_words, valid_inputs, against_string=True,
                against_list=True):
            print_words = input(
                "Would you like to read the story again? (Yes/No) ")

    # Resets game rules in order to check to see if the player wants to play again. print_words switched back to "Yes" so that it would print the words again if the user desired.
    print_words = "Yes"
    game_working = None

    # Checks to see if the user wants to play the game again, "Yes" continues the loop, "No" exits the loop.
    while not verify.valid_input(
            game_working, valid_inputs, against_string=True,
            against_list=True):
        game_working = input("Would you like to make another story? (Yes/No) ")

# If there is any other way you would prefer me to do comments, please let me know, I want to make sure these are sufficient and helpful.
示例#5
0
    # Generates a random score for your rival.
    rival_score = random.randint(0, 100)

    # Creates the letter grade based on the integer given.
    letter_grade = print_letter_grade(grade) + get_plus_or_minus(grade)

    # Prints the appropriate message, based on the integer given.
    print(f"Your grade for the test is {letter_grade}!")
    if rival_score >= int1:
        print("Your Rival got a better grade than you!")
    elif rival_score == int1:
        print("Your Rival got the same score as you!")
    else:
        print("You got a better score than your Rival!")


grading = "Yes"

while grading == "Yes":
    # Gets the input from the user and assigns it to a variable.
    grade = get_user_input()

    # Prints the message based on the input from the user.
    print_grade_message(grade)
    grading = None
    # Checks to see if the user wants to check another grade.
    while not verify.valid_input(
            grading, correct_inputs, against_list=True, against_string=True):
        grading = input("Would you like to enter another grade? (Yes/No) ")
    "Cannot predict now.", "Concentrate and ask again", "Don't count on it",
    "It is certain.", "It is decidedly so.", "Most likely", "My Reply is no.",
    "My sources say no.", "Outlook not so good.", "Outlook good.",
    "Reply hazy, try again.", "Very doubtful.", "Without a doubt.", "Yes.",
    "Yes - Definitely.", "You may rely on it."
]

# Initialized user_input.
user_input = None

# Welcomes the user to the magic 8 ball.
print("----------------------------")
print("Welcome to the Magic 8-ball!")
print("----------------------------")

# While the user is not done asking questions, keep looping responses for each question except for "done".
while not verify.valid_input(user_input, correct_input, against_string=True):

    # Asks what you desire to know.
    user_input = input(
        "What do you wish to know about your future? (enter \"done\" when you are done.)"
    )

    # Checks to see if the user is is done or not.
    if user_input == "done":
        print("Goodbye")
    else:
        # Produces a random response
        print(random.choice(magic8ball))
        user_input = None
# Initilizing characters
valid_inputs = ["Yes", "No"]
set_password_length = None
character_counter = 0
character_types = ""
character_password = ""
user_input = None

# verify.valid_input(set_password_length, is_positive = True, is_numeric = True)

# Checks to see if the users input is valid and then sets the number
# while not set_password_length.isnumeric() or int(set_password_length) < 1:
#     set_password_length = input("Please input a number that will define how long the password will be: ")

while not verify.valid_input(
        set_password_length, is_positive=True, is_numeric=True):
    set_password_length = input(
        "Please input a number that will define how long the password will be: "
    )

# Runs while there are not items in list character_types
while len(character_types) == 0:
    # Checks whether or not the user entered a valid choice for if they wanted
    # capital characters.
    while not verify.valid_input(
            user_input, valid_inputs, against_list=True, against_string=True):
        user_input = input(
            "Would you like capital characters in your password? (Yes/No) ")
        # Appends the character types list to add capital characters.
        if user_input == "Yes":
            character_types += string.ascii_uppercase

# Keeps playing the game if the user wants to.
while user_input == "Yes":
    # Prints the choices.
    print("--------------------------------------")
    print("Rock Paper Scissors Lizard Spock Game!")
    print("R = Rock")
    print("P = Paper")
    print("S = Scissors")
    print("L = Lizard")
    print("K = Spock")

    # Checks to make sure the user uses the correct moves.
    # verify.valid_input(user_move, possible_moves, against_string = True, against_list = True)
    while not verify.valid_input(
            user_move, possible_moves, against_string=True, against_list=True):
        user_move = input("Choose one: ")
        user_move = user_move.upper()

    # Prints User move and computer move
    print(f"You chose {moves_printed[user_move]}")

    # Generates a random move for the computer to use.
    computer_move = random.randint(0, 4)

    # Prints the computers move
    print(f"The computer chose {moves_printed[possible_moves[computer_move]]}")

    # Checks to see what combination victory is made based on the computer
    # move and the user move, then prints the correct victory message.
    if wins[user_move][computer_move] == "D":