def password(x): """ Python HW2: Pt. 1, Password Andrew Noah Woodlee ENG 101-06 Due Date: 12-3-19 password(x) Creates a username and password if both are not in database or certain conditions are met. """ import csv as c Passrow=[] UNamerow=[] if x==True: uiUName=input("Choose a username: ") lenUIUname=len(uiUName) if lenUIUname<6 or lenUIUname>16: print("Input must be between 6 and 16.") return False else: with open('userpass.csv', newline="") as userpass: ruiName=c.reader(userpass,delimiter=',') for row in ruiName: UNmamestr=str(uiUName) if UNmamestr==row[0]: print("Username already taken; pick another.") return False uiPassword=input("Choose a password: ") lenUIPasswd=len(uiPassword) with open('userpass.csv', newline='') as passstr: rUIpasswd=c.reader(passstr,delimiter=',') for PRow in rUIpasswd: uiPasswdStr=str(uiPassword) if uiPasswdStr==PRow[1]: print('Error, password not valid.') return False if lenUIPasswd<6 or lenUIPasswd>16: print("Password input must be between 6 and 16.") return False else: lowercheck=False uppercheck=False numck=False specialchr=False nochr=False special = [126,33,64,35,36,37,94,38,42,60,62] for i in uiPassword: if ord(i) in range(97,122): lowercheck = True elif ord(i) in range(64,91): uppercheck=True elif ord(i) in range(48,57): numchk=True elif ord(i) in special: specialchr=True if not lowercheck: print("You did not include at least one lowercase letter.") return False if not uppercheck: print("You did not include at least one uppercase letter.") return False if not numchk: print("You did not include a number.") return False if not specialchr: print("You did not include a special character.") return False else: with open("userpass.csv",'a',newline='') as UPassA: WUnamePass = c.writer(UPassA, delimiter=',') UNamePWData=[uiUName,uiPassword] WUnamePass.writerow(UNamePWData) return True if x==False: uiUName=input("Choose a username: ") with open('userpass.csv', newline="") as userpass: ruiName=c.reader(userpass,delimiter=',') for UNrow in ruiName: if uiUName==UNrow[0]: uiNameck=True else: print("Username not found.") return False uiPassword=input("Choose a password: ") with open('userpass.csv', newline='') as passstr: rUIpasswd=c.reader(passstr,delimiter=',') for PWckrow in rUIpasswd: if uiPassword==PWckrow[1] and uiNameck: return True else: print("Password not found.") return False def grocery_cost(x): """Andrew Noah Woodlee """ def prime(n): """ Andrew Noah Woodlee ENG 101-06 Hw2 Python Prime Prime(n) Finds nth prime number in range(0,n) """ if n<1: return 0 n=int(n) if n==1: return 2 count = 1 num = 1 while(count < n): num +=2 if is_prime(num): count +=1 return num def is_prime(num): factor = 2 while (factor * factor <= num): if num % factor == 0: return False factor +=1 return True def IO(in_f,out_f): """ Python HW2, IO assignment Andrew Noah Woodlee ENG 101-06 Due Date: 11-14-19 IO(in_f,out_f) Input: in_f is the input filename out_f is the output filename Function reads data in input file and asks for number of points to average and outputs to output file. """ import csv as c C=[] try: # Try to open file with open(in_f, newline='') as In_file: Data = c.reader(In_file, delimiter=",") data = list(Data) p = len(data) del data except FileNotFoundError: # Error for file not found print('Could not find file!') for i in range(0,p): C.append([p]) with open(in_f,newline='') as in_f2: rf=c.reader(in_f2 , delimiter="*") Header=True for rowdata in rf: if Header: Head_Data=rowdata Header=False else: for i in range(0,p): C[i].append(float(rowdata[i])) while True: uiDataPts=input("How many points do you want me to average: ") try: uiDataPts=int(uiDataPts) if uiDataPts < 0: print("Input must be a positve integer, try again.") continue break except ValueError: print("Input must be an integer!") OData=[] """ with open(out_f, 'w', newline='') as outf: OData=c.writer(outf, delimiter=",") OData.writerow(Head_Data) L=len(C[0]) rout=[] n=int(L/uiDataPts) for i in range(0,n): avg=[0.0 for r in range(0,p)] for j in range(0,uiDataPts): for k in range(0,p): avg[k]+=C[k][i*uiDataPts+j] for k in range(0,p): avg[k]/=uiDataPts rout.append[str(avg[k]) OData.writerow(rout)"""