0

I can't figure out why my code isn't weeding out any floats and is letting them run in the while loop (which then screws up the code). Is there something I can do to safeguard the 'while loop' - make it not run whenever a float is put in the input?

Here is my code:

if not a.isdigit() and int(a) < 0 and not b.isdigit() and int(b) < 0 :
     print("Invalid input")     
 else :
     count = 1
     while count < int(b) :
         c = count * int(a)
         print('{} * {} = {}'.format(count, a, c))
         count = count + 1
     c = int(a) * int(b)
     print('{} * {} = {}'.format(b, a, c))
benomatis
  • 5,536
  • 7
  • 36
  • 59

2 Answers2

1

You might need to change those ands to ors so that any of those conditions (a.isdigit(), int(a) < 0, etc.) being true will result in avoiding the loop.

TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
0

Check upfront whether b has decimals:

if round(b)==b: