I’m trying to put the string ‘^’ within a specific index position in my code depending on an awnser, this is my code.
mylist = ['', 'O', '']
from random import shuffle
def shuffle_list(mylist):
shuffle(mylist)
return mylist
def player_guess():
guess = ''
while guess not in ['0', '1', '2']:
guess = input("Pick a number from 0, 1 or 2: ")
return int(guess)
myindex = player_guess()
def check_guess(mylist, guess):
if mylist[guess] == 'O':
print("Correct")
print(mylist)
else:
print('Wrong guess!')
correct_pos = {mylist.index('O')}
print(f"Your guess was at position {guess} the correct position was {correct_pos} \n {mylist} \n")
# INITAL LIST
mylist = ['', 'O', '']
# SHUFFLE LIST
mixedup_list = shuffle_list(mylist)
# USER GUESS
guess = player_guess()
# CHECK GUESS
check_guess(mixedup_list, guess)
I don’t want my output to be this [”,”,’O’] which is the typical output after you have gotten the question wrong I want it to look like [”,”,’O’]
with the ‘^’ symbol right under the ‘O’ on a new line, how would I do something like this and what do I need to add?
>Solution :
This will print out where the O is in the list
def check_guess(mylist, guess):
if mylist[guess] == 'O':
print("Correct")
print(mylist)
else:
print('Wrong guess!')
correct_pos = {mylist.index('O')}
print(f"Your guess was at position {guess} the correct position was {correct_pos} \n {mylist}")
carrot_string = ' '*(3+mylist.index('O')*4) + '^'
print(carrot_string)
the first element starts at position 3 and increases by 4 depending on where its located in the list