Here’s the code:
from random import *
numbers = ['0','1','2','3','4','5','6','7','8','9','10']
r1 = choice (numbers)
r2 = choice (numbers)
print("H = HIGHER ,, L = LOWER ,, S = SAME")
print(r1)
a = input()
print(r2)
if r2 == r1 and a == 's':
print("well done")
if r2 < r1 and a == 'l':
print("well done")
if r2 > r1 and a == 'h':
print("well done")
else:
print("unlucky")
The problem is the very last part of the script. everything works perfectly except at the end of the script just after print(r2)…. It all works but the answer keeps switching between “well done” and “unlucky”. Sometimes it says both. Does anyone know what the problem is? My assumption that this was happening because of the simple reason it is random, and the first output (r1) changes as we move along the script. Any suggestions?
This is a fully functioning version of your program:
I made it more PEP8 friendly. Also, you should be displaying h, l and s… not H, L and S since your comparator against
auses lowercase. Either that, or change the case of the input value. Also, useraw_inputinstead of regularinput.As @Blorgbeard mentions, if you want the same random numbers chosen each time, then add this before you call
choice