project03

py

School

Purdue University *

*We aren’t endorsed by this school

Course

177

Subject

Computer Science

Date

Dec 6, 2023

Type

py

Pages

3

Uploaded by SuperTree11868

Report
#CS 177 - project.py #Jeremiah Budd file2 = "string_bean.py" #Task 1... well its completed kind ugly tho lol def readData(filename): file = open(filename, "r").readlines() fin_tup = () for line in file: if line != "END": line = line.strip().replace(" ", "") line_str = line.split(",") tuple_ = (line_str[0], int(line_str[1])) fin_tup = fin_tup + ((tuple_),) elif line == "END": return fin_tup #Task 2 def calcCollectiblePoints(GoldenRing, PurpleCoin): points_gr = 0 points_pc = 0 if GoldenRing >= 0 and GoldenRing <= 1000: points_gr = .1*GoldenRing if PurpleCoin >=0 and PurpleCoin <= 2: points_pc = 1 elif PurpleCoin >=3 and PurpleCoin <= 5: points_pc = 1.3 elif PurpleCoin >=6 and PurpleCoin <= 8: points_pc = 1.35 elif PurpleCoin >=9: points_pc = 1.40 CollectablePoints = points_gr * points_pc if CollectablePoints <= 100: return CollectablePoints elif CollectablePoints > 100: return 100 def calcStylePoints(Stunt, Emerald): points_st = 0 points_em = 0 if Emerald >= 0 and Emerald <= 10: points_em = 5*Emerald if Stunt >=0 and Stunt <= 10: points_st = 25 elif Stunt >=11 and Stunt <= 30: points_st = 50 elif Stunt >=31 and Stunt <= 50: points_st = 75 elif Stunt >=51: points_st = 100 StylePoints = points_em + points_st if StylePoints <= 100: return StylePoints elif StylePoints > 100: return 100 # Task 3 implementing
file3 = readData(file2) def addData(t): G = 0 P = 0 S = 0 E = 0 R = 0 for i in t: if i[0] == "G": G += i[1] elif i[0] == "P": P += i[1] elif i[0] == "S": S += i[1] elif i[0] == "E": E += i[1] elif i[0] == "R": R += i[1] data = (("G", G), ("P", P), ("S", S), ("E", E), ("R", R)) return data def makeDecision(t): t = addData(t) GoldenRing = t[0][1] PurpleCoin = t[1][1] Stunt = t[2][1] Emerald = t[3][1] Retry = t[4][1] CollectiblePoints = calcCollectiblePoints(GoldenRing, PurpleCoin) StylePoints = calcStylePoints(Stunt, Emerald) total_points = .4 * StylePoints + .6 * CollectiblePoints if Retry ==0: total_points = total_points*1 elif Retry >=1 and Retry <= 3: total_points = total_points*.9 elif Retry >=4: total_points = total_points*.8 if total_points >= 90 and total_points <= 100: rank = 'S' elif total_points >= 80 and total_points < 90 : rank = 'A' elif total_points >= 60 and total_points < 80: rank = 'B' elif total_points < 60: rank = 'C' return (total_points, rank) #print(makeDecision(readData(file2))) #Task 4- file4 = "Performance.txt" #the main function... MEGA function def main(): name = input() data = readData(name) data2 = addData(data)
decision = makeDecision(data) G = data2[0][1] P = data2[1][1] S = data2[2][1] E = data2[3][1] R = data2[4][1] file = open("Performance.txt", "w") file.write(f"Golden Ring: {G}\n") file.write(f"Purple Coin: {P}\n") file.write(f"Stunt: {S}\n") file.write(f"Emerald: {E}\n") file.write(f"Retry: {R}\n") file.write(f"Decision: {decision}") file.close() if __name__ == "__main__": main()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help