#simple question from a simple person, module confusion

9 messages · Page 1 of 1 (latest)

native patrol
#
choice = 0

def numCheck():
    if choice % 2 == 0:
        print("number is even")
    else:
        print("number is odd")


def main():
    print("Even of Odd Checker\n")
    choice = input("enter the number you would like to check:\n")
    numCheck()
    print(choice)
    repeat = input("would you like to conitnue? (y/n)\n")
    print(repeat)
    if repeat != ("y"):
        exit()
    elif repeat == ("y"):
        main()

main()

the answer always comes out even for some reason, ive changed things around so many times but i dont understand why
pretty sure im using module wrong in some way

fallen wedge
#

You should have a look at function arguments

native patrol
agile oracle
#

The issue with this code is that the variable "choice" is not being assigned the value entered by the user in the "main" function. When you call the "numCheck" function, it is evaluating the value of the global variable "choice" which is initialized as O.

To fix this issue, you can pass the variable "choice" as an argument to the "numCheck" function. Additionally, you need to convert the user input from string to integer using the "int()" function. Here is the corrected code:

native patrol
#

i thought of that first problem but i printed choice after i entered number and it would give me the same number so I assumed it was properly changing it

agile oracle
#

Wait I will send you the code

native patrol
#

oh you dont have to do that i just wanted to see what the problem was

#

i want to try and fix it myself

#

thanks for pointing it out though