Python Forum
Ways to check if the variable works. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Ways to check if the variable works. (/thread-3172.html)



Ways to check if the variable works. - AlwaysNew - May-02-2017

Hi this might be a obvious answer but I cant get the random number to display when i put my name as ranNum , This is kind of a dev key to see if the random number works, I know I could just put print (ranNum) but I would like it in the python program. Thanks.
import random
print("Hello \nPlease enter your name")
myName = input()
ranNum = random.randint(1, 100)


if myName == ranNum:
    print (ranNum)
else:
    print ()

I got it working I am really stupid

Just add a variable called devkey = 'ranNum'
then:
if myName == devkey:
print (ranNum)
else:
print ()


RE: Ways to check if the variable works. - buran - May-02-2017

given that you generate random number between 1 and 100, the chance that you enter the same number (even if you call it 'name') is 1 in 100 (probability/statistics).
And if you really input your name and not number it will never print the number.


RE: Ways to check if the variable works. - volcano63 - May-02-2017

(May-02-2017, 08:20 PM)buran Wrote: given that you generate random number between 1 and 100, the chance that you enter the same number (even if you call it 'name') is 1 in 100 (probability/statistics).
... add to that that ranNum is int, and myName is str


RE: Ways to check if the variable works. - wavic - May-04-2017

Hello! You can't compare a string against an integer in your if statement.