How would I take a boolean value as one of my function arguments, and what is the syntax?

Viewed 21

So I'm designing a function for school that needs to take an argument (bool) that in this case would indicate if someone refused a BAC test (true/false) I don't have much experience with bool values, so I'm just wondering what the syntax would be, based off my function. If false, I plan on printing 'fail' before all the other elif/if statements

Thanks, and let me know if you need more info!

def print_roadside_penalty(bac: int, in_num: int, sam_prov: bool):
  
    if ......
    
    elif bac < 50:
        print('no penalty')
    
elif bac >= 80:
        print (fail)
    
elif in_num == 1:
        print('Driving Prohibition Length: 3 days \nVehicle Impoundment Length: 3 days \nPenalties and Fees: $600')
    
elif in_num == 2:
        print('Driving Prohibition Length: 7 days \nVehicle Impoundment Length: 7 days \nPenalties and Fees: $780')
    
elif in_num == 3:
        print('Driving Prohibition Length: 30 days \nVehicle Impoundment Length: 30 days \nPenalties and Fees: $1430')     
1 Answers

Try this:

if not sam_prov:
    print("fail")

This is the same as

if sam_prov == False:
    print("fail")

But its better programming practice to not write == True or == False when evaluating booleans. When you want to know if a boolean is True, you can just say

if sam_prov:

rather than

if sam_prov == True:
Related