Issue raising exceptions – Beginner project /u/benmilesrocks Python Education

Issue raising exceptions – Beginner project /u/benmilesrocks Python Education

Hi everyone!

Trying to make a simple code to handle exceptions. The task is to make a piece of code that checks if an inputted number is between a specified range (in this case -10 to 10). I can make it handle an exception if it falls out of the range, no problem. But I also need a ValueError exception if somebody inputs non numeric values. But I can’t make the ValueError exception work for some reason. Here’s the code:

def read_int(prompt, min, max): try: if prompt in range(min, max): return str(prompt) if prompt not in range(min, max): raise IndexError except IndexError: return “Error: Value not in range ” + str(min) + “, ” + str(max) except ValueError: return “Error: Wrong input” v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v)

v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10)

print(“The number is:”, v)

I’m certain that it’s something REALLY basic that I’m missing here, but I can’t figure it out for the life of me. Please help!!

submitted by /u/benmilesrocks
[link] [comments]

​r/learnpython Hi everyone! Trying to make a simple code to handle exceptions. The task is to make a piece of code that checks if an inputted number is between a specified range (in this case -10 to 10). I can make it handle an exception if it falls out of the range, no problem. But I also need a ValueError exception if somebody inputs non numeric values. But I can’t make the ValueError exception work for some reason. Here’s the code: def read_int(prompt, min, max): try: if prompt in range(min, max): return str(prompt) if prompt not in range(min, max): raise IndexError except IndexError: return “Error: Value not in range ” + str(min) + “, ” + str(max) except ValueError: return “Error: Wrong input” v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v) v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v) I’m certain that it’s something REALLY basic that I’m missing here, but I can’t figure it out for the life of me. Please help!! submitted by /u/benmilesrocks [link] [comments] 

Hi everyone!

Trying to make a simple code to handle exceptions. The task is to make a piece of code that checks if an inputted number is between a specified range (in this case -10 to 10). I can make it handle an exception if it falls out of the range, no problem. But I also need a ValueError exception if somebody inputs non numeric values. But I can’t make the ValueError exception work for some reason. Here’s the code:

def read_int(prompt, min, max): try: if prompt in range(min, max): return str(prompt) if prompt not in range(min, max): raise IndexError except IndexError: return “Error: Value not in range ” + str(min) + “, ” + str(max) except ValueError: return “Error: Wrong input” v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v)

v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10)

print(“The number is:”, v)

I’m certain that it’s something REALLY basic that I’m missing here, but I can’t figure it out for the life of me. Please help!!

submitted by /u/benmilesrocks
[link] [comments]  Hi everyone! Trying to make a simple code to handle exceptions. The task is to make a piece of code that checks if an inputted number is between a specified range (in this case -10 to 10). I can make it handle an exception if it falls out of the range, no problem. But I also need a ValueError exception if somebody inputs non numeric values. But I can’t make the ValueError exception work for some reason. Here’s the code: def read_int(prompt, min, max): try: if prompt in range(min, max): return str(prompt) if prompt not in range(min, max): raise IndexError except IndexError: return “Error: Value not in range ” + str(min) + “, ” + str(max) except ValueError: return “Error: Wrong input” v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v) v = read_int(int(input(“Enter a number from -10 to 10: “)), -10, 10) print(“The number is:”, v) I’m certain that it’s something REALLY basic that I’m missing here, but I can’t figure it out for the life of me. Please help!! submitted by /u/benmilesrocks [link] [comments]

Read more

Problems with using list /u/Easy-Paramedic-5611 Python Education

Problems with using list /u/Easy-Paramedic-5611 Python Education

Alright, basically. I am working on a random script to “find clothes” and clothes are in a list. So we got shoes and all such, in a list. All though i can’t seem to figure out how to print only one of the elements in the list. I originally used “` random.choice(clothes) “` but then i couldn’t figure out how to remove that option from the list, because if that is a choice i’d do that instead

submitted by /u/Easy-Paramedic-5611
[link] [comments]

​r/learnpython Alright, basically. I am working on a random script to “find clothes” and clothes are in a list. So we got shoes and all such, in a list. All though i can’t seem to figure out how to print only one of the elements in the list. I originally used “` random.choice(clothes) “` but then i couldn’t figure out how to remove that option from the list, because if that is a choice i’d do that instead submitted by /u/Easy-Paramedic-5611 [link] [comments] 

Alright, basically. I am working on a random script to “find clothes” and clothes are in a list. So we got shoes and all such, in a list. All though i can’t seem to figure out how to print only one of the elements in the list. I originally used “` random.choice(clothes) “` but then i couldn’t figure out how to remove that option from the list, because if that is a choice i’d do that instead

submitted by /u/Easy-Paramedic-5611
[link] [comments]  Alright, basically. I am working on a random script to “find clothes” and clothes are in a list. So we got shoes and all such, in a list. All though i can’t seem to figure out how to print only one of the elements in the list. I originally used “` random.choice(clothes) “` but then i couldn’t figure out how to remove that option from the list, because if that is a choice i’d do that instead submitted by /u/Easy-Paramedic-5611 [link] [comments]

Read more

Ask Anything Monday – Weekly Thread /u/AutoModerator Python Education

Ask Anything Monday – Weekly Thread /u/AutoModerator Python Education

Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread

Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread.

* It’s primarily intended for simple questions but as long as it’s about python it’s allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban.

That’s it.

submitted by /u/AutoModerator
[link] [comments]

​r/learnpython Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread. * It’s primarily intended for simple questions but as long as it’s about python it’s allowed. If you have any suggestions or questions about this thread use the message the moderators button in the sidebar. Rules: Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban. That’s it. submitted by /u/AutoModerator [link] [comments] 

Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread

Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread.

* It’s primarily intended for simple questions but as long as it’s about python it’s allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban.

That’s it.

submitted by /u/AutoModerator
[link] [comments]  Welcome to another /r/learnPython weekly “Ask Anything* Monday” thread Here you can ask all the questions that you wanted to ask but didn’t feel like making a new thread. * It’s primarily intended for simple questions but as long as it’s about python it’s allowed. If you have any suggestions or questions about this thread use the message the moderators button in the sidebar. Rules: Don’t downvote stuff – instead explain what’s wrong with the comment, if it’s against the rules “report” it and it will be dealt with. Don’t post stuff that doesn’t have absolutely anything to do with python. Don’t make fun of someone for not knowing something, insult anyone etc – this will result in an immediate ban. That’s it. submitted by /u/AutoModerator [link] [comments]

Read more