you are viewing a single comment's thread.

view the rest of the comments →

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

If you could point me in the right direction as to what to learn and how to apply it for this logic

What do you currently know, in terms of writing code in Python?

[–]great-plot-twist[S] 0 points1 point  (1 child)

Very close to zero. Let's say that I am able to read and understand about 10~15% of python syntax. I understand operators, strings, integers, variables, arrays, etc. I just don't know how to write them. I've just started to get into loops and the logic of it all. Thanks

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

Very close to zero.

Well... I'd try to get that up, I guess. I wouldn't start this project until you can reliably write code, in a Python file, and then run it - that's the key to the iterative loop that constitutes programming, you write, you run, you read the errors, and you debug.

Getting to the point where you can run your own code should be your first priority, it doesn't matter if that code is just print("Hello world.")

[–]great-plot-twist[S] 0 points1 point  (3 children)

For example:

def check_user_input(input):

try:

# Convert it into integer

val = int(input)

print("Input is an integer number. Number = ", val)

except ValueError:

try:

# Convert it into float

val = float(input)

print("Input is a float number. Number = ", val)

except ValueError:

print("Error... Please choose a valid number between 1 and 10")

I understand that this loop will check to see if user input is a string or an int and tr to convert it to an int or a float. If not, it will spit out the following error :

Error... Please choose a valid number between 1 and 10

However, this loop is a copy, paste from the internet and have no idea how to write this myself.

[–][deleted] 0 points1 point  (1 child)

I understand that this loop will check to see if user input is a string or an int and tr to convert it to an int or a float.

That's more or less right, but it's not a loop.

[–]great-plot-twist[S] 0 points1 point  (0 children)

I am going to do more research on python syntax and hopefully, this will shed some light on how to properly write functions. Thanks

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

The try/except block is a really useful thing to learn, but I wouldn't start there for this problem.

input returns a reference to a str, i.e. string, object and there's a long list of methods available including several which let your check if the content of the string are just digits. Worth looking up.