correct = ['D','B','C','A','C','D','A','C','C','B','D','A','B','D','C','D','C','D','C','A','B','D','C','B','A'] answers1 = ['A','B','C','A','B','D','A','A','C','B','D','A','D','C','C','B','C','D','B','A','D','D','C','C','A'] answers2 = ['D','A','C','A','B','D','A','C','C','B','D','A','B','D','A','D','C','D','C','A','B','C','C','B','A'] count1 = 0 count2 = 0 for i in range(0,25): if(correct[i] == answers1[i]): count1 = count1 + 1 if(correct[i] == answers2[i]): count2 = count2 + 1 grade1 = int ((count1 / 25) * 100) grade2 = int ((count2 / 25) * 100) print("Student 1 Grade: "+str(grade1)+"%") print("Student 2 Grade: "+str(grade2)+"%")
quantaties = [84, 100, 126, 150, 186, 200, 216, 248] for i in quantaties: if i <+ 100: cost = i * 350 elif i <= 200: cost = (100 * 350) + (i - 300) * 300 elif i > 200: cost = (100 * 350) + (100 * 300) + (i - 200) * 250 print("The cost for an order of",i,"widgets is $" + str(cost)+'.')
balance = 1000 i = 0.05 pmt = 150 n = 0 while (balance > 0): n = n + 1 balance = balance * (i + 1) - pmt round(balance,2) if (balance <= 0): final_pmt = balance + pmt print("The amount of the final payment will be",final_pmt) balance = 0 else: print("The balance at the end of the year",n,'is',balance)
def hailStoneSequence(n): ls = [n] while n != 1: if(n%2 == 0): n = n//2 ls.append(n) else: n = n*3 + 1 ls.append(n) return ls hs15 = hailStoneSequence(15) hs17 = hailStoneSequence(17) hs22 = hailStoneSequence(22) print('hs15: ') for i in hs15: print(i,end = ' ') print('\nhs17: ') for i in hs17: print(i,end = ' ') print('\nhs22: ') for i in hs22: print(i,end = ' ') print()#newline
r_pop = 1000 w_pop = 200 print(f"{'Year':10s}{'R_pop':8s}{'W_pop'}") print(f"-"*24) print(f"{0:<10d}{r_pop:<8d}{w_pop}") r_pop,w_pop = 1100,220 print(f"{1:<10d}{r_pop:<8d}{w_pop}") r_pop,w_pop = 1166, 249 print(f"{2:<10d}{r_pop:<8d}{w_pop}") year = 2 while r_pop>0 and w_pop>0: r_pop_prev = r_pop w_pop_prev = w_pop r_pop = 1.5*r_pop_prev - 0.002*r_pop_prev*w_pop_prev w_pop = 0.8*w_pop_prev + 0.0003*r_pop_prev*w_pop_prev year = year+1 print(f"{year:<10d}{round(r_pop):<8d}{round(w_pop)}")
x1 = 0 x2 = 5 def f(x): result = x**3 - 4*(x**2) + 3*x - 4 return result val1 = f(x1) val2 = f(x2) n = 0 limit = 0.000001 while(abs(val1) > limit or abs(val2) > limit): n += 1 new_x = (x1 + x2)/2 new_val = f(new_x) if new_val < 0: x1 = new_x val1 = new_val else: x2 = new_x val2 = new_val new_x = round(new_x,7) print(f"The approximate solution is x = {new_x}.") print(f"The algorithm took {n} iterations to converge.")
students = { 146832:{'first':'Brendan', 'last':'Small'}, 147354:{'first':'Melissa', 'last':'Robbins'}, 149126:{'first':'Jason', 'last':'Penopolis'}, 149735:{'first':'Fenton', 'last':'Mulley'} } courses = { 'ENGL 101':'Composition I', 'ENGL 104':'Composition II', 'MATH 117':'College Algebra', 'MATH 151':'Calculus I', 'CHEM 103':'General Chemistry I', 'ECON 201':'Macroeconomics' } sid = [149126, 146832, 147354, 149735, 149126, 146832, 146832, 149735, 149126, 147354, 147354, 149735] cid = ['ENGL 101', 'MATH 117', 'ENGL 104', 'CHEM 103', 'MATH 117', 'ECON 201', 'ENGL 101', 'ENGL 101', 'CHEM 103', 'ENGL 104', 'MATH 151', 'MATH 117'] grade = ['D', 'C', 'B', 'A', 'B', 'C', 'A', 'F', 'B', 'A', 'A', 'C'] dash = '-' * 69 print("SID First Last CID Course Name Grade") print(dash) for i in range (0,12): roll = sid[i] code = cid[i] print('{:<8d}{:<9s}{:<10s}{:<11s}{:<22s}{:<1s}'.format(sid[i],students[roll]['first'],students[roll]['last'],cid[i],courses[code],grade[i]))
prices = {'p101':37.52, 'p117':56.98, 'p122':43.72, 'p125':48.33, 'p126':52.45} inventory = { 'STL':{'p101':520, 'p117':315, 'p122':117, 'p125':258, 'p126':345}, 'CHI':{'p101':125, 'p117':864, 'p122':231, 'p125':612, 'p126':164}, 'KC' :{'p101':264, 'p117':285, 'p122':772, 'p125':467, 'p126':106} } total_inventory = {} for key in prices.keys(): quantity = 0 for quant in inventory.values(): quantity += quant.get(key) total_inventory[key] = quantity print(f'{key}:{quantity}') total_value = 0 for key, price in prices.items(): quantity = total_inventory.get(key) total_value += price * quantity print(f'The total value of the inventory is ${total_value}')