-1
print('How many cats do you have?')
numCats = input()
try:
    if int(numCats) >= 4:
        print('That is a lot of cats.')
    else:
        print('That is not that many cats.')
    except ValueError:
    print('You did not enter a number.')
def check_negative(s):
    try:
        if int(numCats) <=0
            print('You cant have negative cats.')
        else:
            print('That is not that many cats.')

I get invalid syntax and im unsure what im doing wrong. Im pretty new to this sort of stuff so nay help is appreciated.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • please don't paste your code as plain text. you can use the markdown syntax to highlight your code. The SO website has good tutorial on how to use markdown. – YaOzI Dec 06 '22 at 01:13

2 Answers2

1

There are a few syntax error in your code, and also you can just add negative check in the try-catch along with >= 4 check.

print('How many cats do you have?')
numCats = input()
try:
    if int(numCats) <0:
        print('You cant have negative cats.')
    elif int(numCats) >= 4:
        print('That is a lot of cats.')
    else:
        print('That is not that many cats.')
except ValueError:
    print('You did not enter a number.')
YaOzI
  • 16,128
  • 9
  • 76
  • 72
0
def check_negatives():
    if numCats < 0:
        print("You cannot have negative cats")


numCats = int(input("How many cats do you have?\n- "))

if numCats >= 4:
    print("That is a lot of cats")
elif 4 > numCats > 0:
    print("That is not many cats")
else:
     check_negatives()

The numCats takes an integer input and the \n adds a new line. It then checks if numCats is greater than or equal to 4, if so, then it prints "That is a lot of cats". If numCats if below 4, BUT also above 0 (so not negative) it prints "That is not many cats". Finally you don't need the check_negatives function since being negative is the only other possibility, but I included it.

You can just leave it at

else:
     print("You cannot have negative cats")
Zesty
  • 7
  • 2