I am in my first weeks of coding and am trying to solve an issue in my code
the challenge: how to inform user that his input is not in the alphabet and subsequently return him to the input line without continuing the code.
the code i have
import random
import re
print(" _______\\__")
print(" (_. _ ._ _/")
print(" '-' \__. /")
print(" / /")
print(" / / .--. .--.")
print(" ( ( / '' \/ '' \ || || /\ |\ | _____ |\ /| /\ |\ |")
print(" \ \_.' \ ) ||--|| /__\ | \ | | ___ | \/ | /__\ | \ |")
print(" || _ './ || || / \ | \| |____| | | / \| \|")
print(" |\ \ ___.'\ /")
print(" '-./ .' \ |/")
print(" \| / )|\'")
print(" |/ // \\")
print(" |\ __// \\__")
print(" //\\ /__/ \__|")
print(" .--_/ \_--.")
print(" /__/ \__\'")
name_user = str(input("What is your name?:"))
print("Hello,", name_user, "lets play HangMan, try to guess the word i have challenged you with?")
word_list = ["fireboard", "identical", "chocolate", "christmas", "beautiful", "happiness", "wednesday", "challenge", "celebrate"]
random_pick = random.choice(word_list)
random_pick_a = re.sub("[a-z]","*", random_pick)
random_pick_list_a = list(random_pick_a)
print(random_pick)
count = 0
def main_function():
global count
while count <= 9:
user_input = str(input("type a letter:"))
for i, c in enumerate(random_pick):
if c == user_input.casefold():
random_pick_list_a[i] = user_input.casefold()
random_pick_list_b = ''.join(random_pick_list_a)
if random_pick_list_b == random_pick:
print("done")
exit()
else:
continue
else:
if user_input.casefold() not in random_pick:
count = count+1
print(count)
if count == 10:
print("sorry")
exit()
print(random_pick_list_b)
main_function()