Search code examples
pythonoutputboolean-expression

How can I add a line of code to reverse the output of my program?


I'm having trouble with my homework assignment. The assignment was to create a "Can I become the President?" program, and have the output be True if the answer was yes and False if the answer was no.

The next step of the assignment was to add one line of code so that the program prints True if the user cannot be President, and False if they can. This is where I got stuck.

(Please keep in mind I just joined this class 2 weeks ago)

This is what I have so far:

age = int(input('How old are you? '))
born_in_us = (input('Were you born in the US? '))
residence = int(input('How long have you lived in the United States? '))
print(age >= 35 and residence >= 14 and born_in_us == 'Yes')


Solution

  • You can assign your condition to a variable

    eligible = age >= 35 and residence >= 14 and born_in_us == 'Yes'
    

    then the first version of the assignment can be

    print(eligible)
    

    and the latter can be modified to

    print(not eligible)