How to separate code

Thanks. And what do you infer from these? Let’s look at the code and the
output together. I’ll Intersperse them below:

 licensekey = input("Enter License Key")
 print( type(licensekey), repr(licensekey) )

 <class 'str'> ' 824'

This shows us that you’ve entered the string ' 824'.

 licensekey = 824

Then you completely forget what you entered, and just set licensekey
to 824. Which is fine for debugging to see what an 824 does. But
better is to convert the string you entered into an integer. See my
earlier post.

 print( type(licensekey), repr(licensekey) )

 <class 'int'> 824

This shows us that licensekey is now an int (an integer) with value
824 (notice that there are now no quote marks - this is a number, not
a string).

 if licensekey>=824:
     print("license key invalid rerun and try again")

     license key invalid rerun and try again

This shows us that we took the “true” branch of the if-statement. That
is because your test licensekey>=824 evaluated as true. Since
licensekey is 824, we are testing: 824>=824. That looks true to
me.

If this should not have taken the “true” branch, how do you think the
test should be changed so as to produce “false”?

its looks like i have solved it with chatgpt, thank you for your help

It is considered polite to post your solution and a summary of how you arrived at it.

1 Like

it looks like i have solved it with chatgpt, thank you all for helping me :grin:

the solution was:

# Prompt the user to enter the license key
licensekey = input("Enter License Key: ")

# Print the type and representation of the entered license key
print(type(licensekey), repr(licensekey))

# Convert the entered license key to an integer
try:
    licensekey = int(licensekey)
except ValueError:
    print("Invalid input! License key must be a number.")
    exit()

# Check if the entered license key is valid
if licensekey != 824:
    print("License key invalid. Rerun and try again.")
else:
    print("License key is valid!")

when i ran that code it didnt run the incorrect input when i inputted the correct code

1 Like