Message323067
Ideas like this are better sent to the python-ideas@python.org mailing list for discussion rather than immediately opening an issue. Note though that I think this has a low chance of acceptance; there's a very high bar to clear to add syntax, even higher for new keywords, and this doesn't seem to buy much over:
while True:
try:
num = int(input("Enter a number: "))
except ValueError:
print("I said a *number*")
else:
break
print("The square of your number is", num**2)
Especially considering that this version allows you to handle the error however you want, and handle different errors differently, rather than just silently restarting the loop no matter the error.
Also, this will be valid in 3.8 and achieve exactly what you're asking for:
while not (ans := input("Enter a number: ")).isnumeric():
pass
print("The square of your number is", int(ans) ** 2)
Do feel free to send your idea to python-ideas anyway, I'm just one opinion :) |
|
Date |
User |
Action |
Args |
2018-08-03 19:52:12 | zach.ware | set | recipients:
+ zach.ware, Happy Fakeboulder |
2018-08-03 19:52:12 | zach.ware | set | messageid: <1533325932.45.0.56676864532.issue34332@psf.upfronthosting.co.za> |
2018-08-03 19:52:12 | zach.ware | link | issue34332 messages |
2018-08-03 19:52:12 | zach.ware | create | |
|