1MagicNumber = []
2confirmation = "Confirm"
3Cancel = "Cancel"
4
5for n in range(5):
6 # prompting user to enter the magic number
7 try:
8 user = int(input("Please Enter your Magic number: "))
9 # add user number to the list
10 MagicNumber.append(user)
11 # user confirmation to continue or cancel the process
12 if True:
13 print(f"The value you enter was : {user}")
14 UserConfirm = input(" Enter Confirm to Continue or cancel to Cancel: ")
15 if UserConfirm == confirmation:
16 continue
17 elif UserConfirm == Cancel:
18 break
19 # in case the user enter a wrong confirmation keyword instead of confirm or Cancel
20 else:
21 print("------------------------------------------")
22 print("Not a correct input, Please try again!!!")
23 print("------------------------------------------")
24 if True:
25 print("The Number you enter was : ", user)
26 UserConfirm = input(" Enter Confirm to Continue or cancel to Cancel: ")
27 if UserConfirm == confirmation:
28 continue
29 elif UserConfirm == Cancel:
30 break
31 # if user enter a wrong type of number (ex:string or float) instead of throwing an error
32 # user receive a message
33 except ValueError:
34 print("wrong type of number, Prefer integer")
35
36print("Your Magic Number are: ", MagicNumber)