+ 2
Please help me in python /lambda and exception
i want from user the input(int) , and if the user input was string (ValueError) i make the user inter again all of this by try: lambda except: please any one help me๐
17 Answers
+ 6
could be like that
age=lambda: int(input(" inter your age"))
noinp = True
while noinp:
try:
age()
noinp = False
except ValueError:
print("error inter real age")
+ 5
oh Code Crasher you know me right?
I am addicted to this kind of questions.
Yes.... why....????
to see if it works.
Useless like climbing Mount Everest but funny.
+ 2
I also like to write oneliner block-monsters once in a while, for the sake of it.
When I write 'serious' code, I'll always choose the simplest tool that properly does the job, just as I wouldn't use a butter knife, a scalpel, a dagger and a katana interchangeably.
+ 1
We can not write the code for you, only assist. Please show us your attempt first!
+ 1
what the problem here
try:
age=lambda: int(input(" inter your age"))
except ValueError:
print("error inter real age")
age()
age()
+ 1
thank,s pro๐๐
+ 1
thank,s bro i,ll do that...
+ 1
no problem pro...
i was think that is better to shaeiring aknowlegement
while True:
print("Thank you for all๐๐๐")
+ 1
Code Crasher, that's also the reason I'm *not* typically seen in that sort of question.
'Write a program that does x, but you can't use y, however, instead you have to use magical, popular and overrated language feature z...'
I just don't see how this would help anybody in real life. It only comes up as constructed questions of mediocre tutorials. #opinion off
This is the way I'd do it basically always:
while True:
inp = input().strip()
if inp.isdigit():
break
# turn inp to int and do whatever
No try/except or lambda, but why use a machine gun against mosquitos in the first place? #opinion now really off
0
but i want to use a lambda
what,s true for that
0
age()
that calling a lamda and the code was runned
0
USA ๐
0
no๐iam speak arabic but i inderstand you as a good
0
i wil do this idea thank you realy
love your help so match๐
0
what is your name in facebook
or give me your phone in whatsapp please๐
0
oma falk ..yes it,s๐