-1

my for loop is looping through a list and i want tomake it so that if a value a user enters a value it its is not found in the list iwant to get another value from the user to check for in the list

import datetime as date
x = date.datetime.now()
D = []
d = int((x.strftime("%d")))
M = (x.strftime("%B"))
for i in range(1,8):
d = d + 1D.append(d)
print (M+", "+str(d))
z = str(input("enter date for booking"))
for i in D :
    if i == z:
        break
  • check out the `else` clause that `for` supports. – JonSG Mar 22 '22 at 14:39
  • 3
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – 001 Mar 22 '22 at 14:41

1 Answers1

0
while True:
  
  x = int(input("Enter a Value : "))
  if x not in list:
    print("Try again") 
    continue
  print("Whatever you want to print")
  break

This could help you with your project. If the variables are integers, keep it as int but you could switch it to str or float according with your variable types.