This might be a strange question. I have the beginning and the end... but not sure how to connect the two.
I'm writing a program that asks for a positive integer.
How can I make use of this code snippet:
If I can't do this then I can write a workaround to test for integer and/or string... but I wanted to try this different approach.
Thanks!
Never mind. Not sure I know what I'm talking about with this!
I'm writing a program that asks for a positive integer.
How can I make use of this code snippet:
if type(n) != int: raise TypeError("n must be a positive integer") if n < 1: raise ValueError("n must be a positive integer")The preceding line is:
n = input("What term of the Fibonacci Sequence would you like to know? ")The problem is input takes a string, which means I will always get the TypeError. I want the errors to occur only if a bona fide decimal is entered (e.g. 1.5) or a negative integer or letters. I don't want the input filtered (e.g. automatically changed to a string).
If I can't do this then I can write a workaround to test for integer and/or string... but I wanted to try this different approach.
Thanks!
Never mind. Not sure I know what I'm talking about with this!