+ 2

How do I fix this?

I have a problem with python. I want to make a code that recognizes the person if you type a certain thing. I put the exact same thing but it gets the "No one recognized" print instead of the "Oh.. this is (Name)". I hope I can get an answer. Code: user_input = input() VDP = 229998043833 G.A = 192847102401 if type(user_input) == VDP: print("Oh.. This is VDP!") elif type(user_input) == G.A: print("Oh.. That is VDP's friend!") else: print("I can't recognize the person!")

10th Nov 2021, 8:02 PM
VaggelisDaPro
VaggelisDaPro - avatar
4 Answers
+ 2
If you wanted to test for types then you would've just done like this VDP = 229998043833 GA = 192847102401 user_input = int(input()) if type(user_input) == type(VDP): print("Oh.. This is VDP!") if type(user_input) == type(GA): print("Oh.. That is VDP's friend!") else: print("I can't recognize the person!")
10th Nov 2021, 8:26 PM
John Delvin
John Delvin - avatar
+ 5
input() returns a string (str) type. VDP is a numerical type, as is G.A (FYI unless G is an imported value, class, or instance etc, you shouldn't use .A, maybe use G_A instead). You can either change the values of VDP and G.A to strings or convert the input() values to the correct type using int() prior to comparison.
10th Nov 2021, 8:16 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
When you compare the variables, also make sure that both are int or str and G.A is not a valid variable name due to the .
10th Nov 2021, 8:17 PM
Lisa
Lisa - avatar
+ 1
in your case if the user inputs not only digits you will get an error, so you should handle it: VDP = 229998043833 G_A = 192847102401 try: user_input = int(input()) if user_input == VDP: print("Oh.. This is VDP!") elif user_input == G_A: print("Oh.. That is VDP's friend!") else: print("I can't recognize the person!") except: print("I can't recognize the person!") without "try" you can go this way: user_input = input() VDP = "229998043833" G_A = "192847102401" if user_input == VDP: print("Oh.. This is VDP!") elif user_input == G_A: print("Oh.. That is VDP's friend!") else: print("I can't recognize the person!")
12th Nov 2021, 3:45 AM
Aliaksandr Khilko
Aliaksandr Khilko - avatar