magic number python code example
Example 1: python magic number
MagicNumber = []
confirmation = "Confirm"
Cancel = "Cancel"
for n in range(5):
try:
user = int(input("Please Enter your Magic number: "))
MagicNumber.append(user)
if True:
print(f"The value you enter was : {user}")
UserConfirm = input(" Enter Confirm to Continue or cancel to Cancel: ")
if UserConfirm == confirmation:
continue
elif UserConfirm == Cancel:
break
else:
print("------------------------------------------")
print("Not a correct input, Please try again!!!")
print("------------------------------------------")
if True:
print("The Number you enter was : ", user)
UserConfirm = input(" Enter Confirm to Continue or cancel to Cancel: ")
if UserConfirm == confirmation:
continue
elif UserConfirm == Cancel:
break
except ValueError:
print("wrong type of number, Prefer integer")
print("Your Magic Number are: ", MagicNumber)
Example 2: python "in magic method"
>>> y = [5, 4, 3, 2, 1]
>>> y.__contains__(3)
True
>>> y.__contains__(6)
False