0

How to terminate it?

How to terminate this program when user guess correct number? In this program when user enter corret number, that time prgoram also execute other repetitive code rather then terminating, I just want to terminate it This is my code - import random print("Welcome to the Number Gussing Game!") print("I'm thinking of a number between 1 to 100.") level = input("Choose difficulty. type 'hard' or 'easy': ").lower() HARD_LEVEL = 5 EASY_LEVEL = 10 continue_go = True for_checking= True num_list = [] for i in range(1, 101): num_list.append(i) # print(num_list) choose_num = random.choice(num_list) # print(choose_num) def checking_num(attmp): print(f"You have {attmp} attempts remaining to guess the number") user_num = int(input("Make a guess: ")) if user_num == choose_num: return f"You guess right number is {user_num}" elif user_num > choose_num: return "Too high. \n No this is not." elif user_num < choose_num: return "Too low. \n No this is not." def level_checking(hard_easy): while hard_easy != 0: print(checking_num(hard_easy)) hard_easy -= 1 if hard_easy == 0: print(f"Ohh no!!! You loss the number is {choose_num}") while continue_go: if level == "hard": level_checking(HARD_LEVEL) continue_go = False elif level == "easy": level_checking(EASY_LEVEL) continue_go = False

26th Jun 2021, 6:18 PM
Gayatri Dunakhe
Gayatri Dunakhe - avatar
1 Odpowiedź