Thank you so much for the help, I didn’t know I could force an integer
like that.
No worries.
It isn’t a “force”. The int() constructor accepts a str as a valid
argument. But if you give it a bad string, it won’t “force” it to be an
int anyway, it will fail instead:
int("not a number")
number_2 = [input("Type a number: "), 100]
Why make a list here instead of just using 2 variables?
number_2_mine = int(number_2[0])
def big_number_also(number_sec, number_big_sec):
if number_sec >= number_big_sec:
print(f"{number_sec} is a big number!“)
elif number_sec < number_big_sec:
print(f”{number_sec} is not a big number.")
Since failing “number_sec >= number_big_sec” implies that “number_sec <
number_big_sec” your “elif” line should just be “else:”.
It will have the same meaning, but by putting a condition in the elif
you’re forcing the reader to look at that condition to determine when it
fires. With an “else:” the reader knows it always fires if the
previous condition (in the “if”) failed.
The natural supposition with “if… elif …” is that there are 3
possible outcomes: the first for the “if”, a second for the “elif” and a
third for when neither applies.
big_number_also(number_2_mine, number_2[1])
If you use 2 variables such as “number_2_s” and “threshold” you don’t
need to index number_2 - the expressions “number_2[1]” and earlier
“number_2[0]” are not obviously a threshold value. Whereas you could
just name it “threshold” or something similar.
In a programme this small the issue is small, but in a larger programme
your “def big_number_also” might well be far from where you call it, so
having a good name for the values conveys more meaning to someone
reading the code (even you, some time later).
Cheers,
Cameron Simpson cs@cskk.id.au