r/learnpython • u/Alive_Hotel6668 • 29d ago
I am tryoing to take innput from user, but if it is of the wrong data type or doesnt mathc the condition then i want to restart the process of asking input
I have put toghether this code but it doesnt work
while c==1:
C_ID=int(input('enter customer id'))
locn(C_ID,8)
Customer_name=input('enter customer name')
locv(Customer_name,40)
Number=int(input('enter contact number'))
locn(Number,10)
Delivery_status=input('enter delivery status')
locv (Delivery_status,10)
value=(C_ID,Customer_name,Number,Delivery_status)
cur.execute('insert into customer values{}'.format(value,))
cur.commit()
if c==0:
c=1
def locv (x,y):
if len(x)>y:
print('the string should not exceed ',y,' characters long' )
c=0
def locn(x,y):
if len(str(x))!=y:
print('the nermber should be',y,' long')
c=0
this program is for creating an sql user interface via python, The conditions for the input has been put into the udf. Now with the current version the code continues even if the input from the user doesnt match the given conditions.
(Please ignore the indentation, in the actual code it is fine but while copying here something happneded to it.
What do i do to restan the process of taking input from the user?
Thanks in advance!