#!/usr/bin/env python # coding: utf-8 # In[8]: # Sections 3.3 -- comparing strings # Consider this code: # the below code yields "false" #name1='tom' #name2='jim' #print("name1= ACUTOFF: print("You got an A") elif current_grade >= BCUTOFF: print("You got a B") elif current_grade >= CCUTOFF: print("You got a C") elif current_grade >= DCUTOFF: print("You got a D") else: print("You got an F :(") # In[34]: # Section 3.5 Logical Operators # Idea: combine multiple boolean operators into one # Logical Operators Meaning # and both must be true to get true # or at least one has to be true (both could be true) # not reverses the truth -- e.g. not == is same as != #Examples x=2 y=3 a=4 b=5 z=2 print('xy and ay and ax is',not y>x) # Truth tables # EXPR | not EXPR # --------------- # T | F # F | T # # EXPR1 | EXPR2 | EXPR1 and EXPR2 | EXPR1 or EXPR2 # T | T | T | T # T | F | F | T # F | T | F | T # F | F | F | F # # # # In[42]: # Loan program -- check if user qualifies for a loan where qualifies means # salary at least 30,000 and years on job at least 2 # magic numbers SALARY_CUTOFF=30000 JOBYEARS_CUTOFF=2 #get user information salary=float(input("What is your annual salary?")) years=float(input("How many years have you worked in your job?")) # check the condition of qualification: if salary >= SALARY_CUTOFF and years >= JOBYEARS_CUTOFF: print("Congratulations you owe us money later -- you got the loan.") else: print("we're sorry to tell you you did not get the loan so you can't pay us for 30 years") # In[43]: #checking numerical ranges #How do we check if a number is in a numerical range #like [20,40] (this is the closed interval of numbers between 20 and 40 including both)? valuetocheck=float(input("What value do you want to check?")) if(valuetocheck >= 20 and valuetocheck <= 40): print("The inputted number is in the interval [20,40]") else: print("The inputted number is not in the inerval [20,40].")