Home > Net >  I'm trying to add code onto this which allows me to check and give a response if i enter a nega
I'm trying to add code onto this which allows me to check and give a response if i enter a nega

Time:12-06

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.

CodePudding user response:

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.')
  • Related