I am trying to program hangman. I am quite new and am wondering something. I already figured this out
x = "Hello World"
print(x[2])
print(x[6])
print(x[10])
The output is
l
W
d
I am wondering if i can write this:
import random
list = ["Hi","Hello","Hi wrld","Hello world"]
chosen = list(random.randint(1,4)
nr_of_letters = len(chosen)
# j is the letter the user guesses
j = input()
if j == chosen[0,nr_of_letters]:
print("something")
else:
print("something else")
The error info I get is that the number has to be an integer. If I try writing it differently I have 2 options.
#the first option is :
j = int(input ())
#the second option is:
if j == chosen[0,int(nr_of_letters)]:
neither of them work. Please how can I write that correctly.
chosen = list[random.randint(0,3)]