Page 1 of 1

Python Programming Question

Posted: 03 Feb 2023, 23:11
by gaxijiw
Hi guys,



Im trying to teach myself python and I am trying to create a program that compares a randomly generated letter to a letter that a user chooses. For some reason though, the program will think that the user's letter(h for example) is equivalent to some random letter like j. I don't know if I'm comparing the functions incorrectly or what, but any help would be much appreciated. Thanks



import random

def randomsentence():
abc = 'abcdefghijklmnopqrstuvwxyz '
randomstring = str(random.choice(abc))
return randomstring

def userstring():
user = 's'
return user

def comparison():
while userstring() != randomsentence():
print("There is currently no match")
if randomsentence() == userstring():
print(f"There is a match, user generated is {userstring()}, the random generated is {randomsentence()}")
break
comparison()