mardi 24 décembre 2019

How to compare the type of the var? [duplicate]

This question already has an answer here:

I've began a very basic program where you have to find the number randomly chosen by the computer. I successfully added the randomizer to the program, yet I couldn't find how to compare the type of the asked number so that a message is printed whenever you type letters instead of numbers for example.

I tried this type of command

if type(nbredevine)!=int:

    print ("""I asked you for an integer. Don't mess with me.""")

unfortunately this isnt working, and even though I've searched for it in the internet and on this site, i haven't been able to find something that fits this special situation.

I haven't been able to make the isinstance function work in this case. Is it because I'm too much of a neophyte ?

Thank you guys, and happy holidays for those of you who are in holidays.

Aucun commentaire:

Enregistrer un commentaire