Sum of numbers + error if text entered

Hi all,
I am a beginner. I need to request a user to enter a number and do the sum of those numbers which I have but I also need to identify if the value entered is not a number and show an error message. Any help? I’m doing it with ‘for in’ loop.
I was thiking to do it as the substraction of the value entered minus the value entered should be zero, otherwise is not a number? But is there another way?
Thanks

Show us some code, friend.

Thanks for responding so quickly Colin. This is what I have. I think I should check if it’s an enteger first, then show an error message, and if it is an enteger, then do the sum?

num = int(input("Please enter a number: "))

sum = 0

for value in range(1, num + 1):
    sum = sum + value
    
print(sum)

Assuming python:

if type(num) == int or type(num) == float:
    # It's a number
else:
    # Not a number

If this is Python, you should post it in the Python-subforum.
Then for this kind of thing you’d use a “try-except” block.

It’s in python yes Jenovs.
I’ll try to incorporate that.

Thank you

Thank you Jagaya. Sorry about that. New to this.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.