1

I have variable d int.

d = int(input("1 - to enter expression; 2 - to enter text; 3 - to exit. "))

But if you do not enter a number then the program crashes with an error. To avoid this I write this:

d = (lambda x = input("1 - to enter expression; 2 - to enter text; 3 - to exit. "): int(x) if x.isdigit() else: 3)

but get an error

SyntaxError: invalid syntax.

Garmahis
  • 13
  • 1
  • 3

1 Answers1

2
d = input("1 - to enter expression; 2 - to enter text; 3 - to exit. ")
try:
    d = int(d)
except ValueError:
    d = 3  # the default value
Ionut Hulub
  • 6,180
  • 5
  • 26
  • 55