Skip to main content
added 374 characters in body
Source Link
Liju
  • 2.3k
  • 3
  • 8
  • 21

Below code may help.

age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

If you want to have maximum tries, say 3, use below code

age=(lambda i,n,f: f(i,n,f))(input("Please enter your age: "),1,lambda i,n,f: i if i.isdigit() else (None if n==3 else f(input("Please enter your age: "),n+1,f))) print("You are able to vote in the united states" if age and int(age)>=18 else "You are not able to vote in the united states",end='') 

Note: This uses recursion.

Below code may help.

age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

Note: This uses recursion.

Below code may help.

age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

If you want to have maximum tries, say 3, use below code

age=(lambda i,n,f: f(i,n,f))(input("Please enter your age: "),1,lambda i,n,f: i if i.isdigit() else (None if n==3 else f(input("Please enter your age: "),n+1,f))) print("You are able to vote in the united states" if age and int(age)>=18 else "You are not able to vote in the united states",end='') 

Note: This uses recursion.

added 28 characters in body
Source Link
Liju
  • 2.3k
  • 3
  • 8
  • 21

Below code may help.

#Read age from user age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) #Check the age and print message print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

Note: This uses recursion.

Below code may help.

#Read age from user age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) #Check the age and print message print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

Below code may help.

age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 

Note: This uses recursion.

Source Link
Liju
  • 2.3k
  • 3
  • 8
  • 21

Below code may help.

#Read age from user age=(lambda i,f: f(i,f))(input("Please enter your age: "),lambda i,f: i if i.isdigit() else f(input("Please enter your age: "),f)) #Check the age and print message print("You are able to vote in the united states" if int(age)>=18 else "You are not able to vote in the united states",end='') 
Post Made Community Wiki by Liju