<jupyter_start><jupyter_text>3.1 Boolean expressions3.1.1 Class bool:- Ture: Any nonzero number is interpreted as "Ture" in bool - False3.1.2 Comparison operators- not equal        (!=)- greater than     (>)- less than        (<)- greater or equal (>=)- less or equal    (<=)- the same as      (is)- not the same as  (is not) 3.2 Logical operators 3.3 Conditional execution (if)3.3.1 Example<jupyter_code>x = 3
if x>0:
    print("x is positive")<jupyter_output>x is positive<jupyter_text>3.3.2 Using pass as place holder<jupyter_code>if x<0:
    pass<jupyter_output><empty_output><jupyter_text>3.4 Alternative execution (else)<jupyter_code>if x>0:
    print("x is positive")
else :
    print("x is negative")<jupyter_output>x is positive<jupyter_text>3.5 Chained conditionals (elif)- Each condition is checked in order- Even if more than one condition is ture, only the first true branch executes.<jupyter_code>if x>0:
    print("x is positive")
elif x == 0:
    print("x is zero")
else :
    print("x is negative")<jupyter_output>x is positive<jupyter_text>3.6 Nested conditionals- Nested conditionals become difficult to read very quickly. - In gereral it is a good idea to avoid them when you can.<jupyter_code>if 0< x:
    if x<10:
        print("x is a positive single-digit number")
if 0 < x and x < 10 :
    print("x is a positive single-digit number")<jupyter_output>x is a positive single-digit number<jupyter_text>3.7 Catching exceptions using try and except<jupyter_code># Convert a Fahrenheit temperature to a Celsius temperature
inp = input('Enter Fahrenheit Temperature:')
try:
    fahr = float(inp)
    cel = (fahr - 32)*5/9
    print(cel)
except:
    print('Please enter a number')<jupyter_output>Enter Fahrenheit Temperature:o
Please enter a number<jupyter_text>3.8 Short-circuit evaluation of logical expressions3.8.1 Short-circuiting the evaluation:- When the evaluation of a logical expression stops because the overall value is already known.- The below expression get no error as `(x/y)>2` is not evaluate<jupyter_code>x = 1
y = 0
x >= 2 and (x/y)>2<jupyter_output><empty_output><jupyter_text>3.8.2 Guardian pattern:- Using the short-circuit method to make expression right<jupyter_code>x = 6
y = 0
x > 2 and (x/y) > 2
x > 2 and y != 0 and (x/y) > 2<jupyter_output><empty_output><jupyter_text>3.9 DebuggingIn general, error messages indicate where the problem was discovered, but the actual error might be earlier in the code, sometimes on a previous line. 3.10 Glossary- __traceback__ A list of the functions that are executing, printed when an exception occurs.<jupyter_code># exe 3.1
hrs = input("Enter Hours:")
h = float(hrs)

rate_per_hour = input('Enter Rate per hour:')
r = float(rate_per_hour)

if h<=40:
    Pay = h*r
else:
    Pay = r*40+(h-40)*r*1.5
    
print("Pay:" + str(Pay) )
# exe 3.2
hrs = input("Enter Hours:")
rate_per_hour = input('Enter Rate per hour:')
try:
    h = float(hrs)
    r = float(rate_per_hour)
    if h<=40:
        Pay = h*r
    else:
        Pay = r*40+(h-40)*r*1.5

    print("Pay:" + str(Pay) )
except:
    print("Error, please enter numeric input")
# exe 3.3
score = input("Enter Score: ")
s=float(score)

if s>1:
    print('Err: input out of range')
elif s<0:
    print('Err: input out of range')
elif s>= 0.9:
    print('A')
elif s>=0.8:
    print("B")
elif s>=0.7:
    print("C")
elif s>=0.6:
    print("D")
else:
    print("F")<jupyter_output>Enter Score: 0.95
A
{'fraction_non_alphanumeric': 0.12106184364060676, 'fraction_numerical': 0.029754959159859977, 'mean_word_length': 3.97677793904209, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '626160', 'license': 'MIT', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1196, 'n_words': 400, 'path': 'Python4Every1/Chapter 3 Conditional execution.ipynb', 'repo_name': 'qiyangjie/Python4Every1-KeyNotes', 'size': '3428'}