<div dir="ltr"><span style>Hi everyone,</span><br clear="all" style><div style><br></div><span style>I am new to python and have a noob question.</span><div style><br></div><div style>Is it generally better to use try/except/else statements or if/elif/else? Or, is there a time and place for each?</div>
<div style><br></div><div style>For a simple example, assume I want a user to enter a number</div><div style><br></div><div style>1) try:</div><div style> number = float(input('enter a number: ')</div><div style>
except ValueError:</div><div style> print('enter a number.')</div><div style> else:</div><div style> print('you entered a number')</div><div style><br></div><div style><b>OR</b></div><div style>
<b><br></b></div><div style>2) number = float(input('enter a number: ')</div><div style> if number >=0 or < 0:</div><div style> print('you entered a number')</div><div style> else:</div>
<div style> print('enter a number.')</div><div style><br></div><div style>Thanks for the help.</div><br>
</div>