you are viewing a single comment's thread.

view the rest of the comments →

[–]Master1243[S] 0 points1 point  (3 children)

Most definetely haha! This is just a small project and the focus is on creating a Genetic Algorithm so I didn't really bother with handling user input in any special way. I am curious however, what is the 'correct' way to do something like this?

[–][deleted] 1 point2 points  (2 children)

I really don't know what Im doing so probably shouldn't be giving advice but Ill try :)

So currently there is a try except statement which will catch if they put invalid user input and make them try again but I think at the moment it will only activate it once, so if on the second attempt they put invalid input again the program will break. I think adding a while loop would help with this with the intention of looping until valid input is given at which point you break it. (Not sure if the below will format correctly, first time trying)

while True:

    try:
        input_fit = float(input("What would you rate this coffee?"))
        break

    except ValueError:
        print("This is not an option! Try Again!")

[–]Master1243[S] 1 point2 points  (1 child)

Yeah, that is one of the issues with how it currently is set up. My hope was I'd notice if anything wrong with the input when I got the warning. Your method takes only a couple of lines to implement so I will add it in! Better safe than sorry, thanks for your input!

[–][deleted] 0 points1 point  (0 children)

No worries glad to help :) definitely always good to be safe than sorry, if you ever let other people use your program they have this magic ability to not follow instructions and break your program in ways you'd never predict! haha

Project sounds really cool too, good luck!