1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How could I put this in a defined variable? and also prevent floating numbers?

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024 às 22:32.

  1. Stack

    Stack Membro Participativo

    I have been given my first college assignment, its just a game where you have a user put in words to create a random story. although its not mandatory I want to add some sort of verification to prevent people putting in numbers and strings less than 3 characters long. This code does work for its purposes but I have a lot of repetitive, bloated code i want to clear up. The code doesn't prevent floating numbers or negative numbers and I am assuming it has something to do with me not using .isalpha some way or another.

    adjective1 = input(f"{name}, give me any adjective.\n")
    while adjective1.isdigit() or len(adjective1) <= 2:
    print("That's not a valid input!")
    adjective1 = input(f"{name}, give me an adjective.\n")


    I have tried defining a variable and naming it verify. I used a while loop in it but im not getting the same results as I currently do

    Continue reading...

Compartilhe esta Página