python - calling up function not working -
def td(): choice = input("\nwhich trainning event access?\n1.swimming\n2.cycling\n3.running\n4.comare data\n5.final eight\nplease type in number before event of want choose\n") if choice == "1": ################################################ swim() # call function depending on option user choices, function take user menu elif choice == "2": cyc() elif choice == "3": run() elif choice == "4": comp() elif choice == "5": eight() ###################################################### def swim(): swimming_file_exists = exists("swimming_file.txt") # create swimming has 'txt' in or swimming file exsits if swimming_file_exists == false: # if file doesnt exsit create swimming_file = open("swimming_file","w") # allows user write file swimming_file.close swimming_file = open("swimming_file","a") # open "a" mode write position @ end of file else: swimming_file = open("swimming_file","a") totaldistance = input("what total distance swam in meters?") totaltime = input("how long did swim in minutes?") speed = totaldistance/totaltime # formula speed user doesnt have work out speed swimtype = input("\nwhich style did swim\n1.slow freestyle\n2.fast freestyle\n3.backstroke\n4.breaststroke\n5.butterfly\n\nplease type in number before swimming style\n") print ("make sure these right values. if not pres ctrl z undo mistakes") time_hours = totaltime / 60 # turns minutes swam hours able calculate calouries have burnt if swimtype == "1": calb1 = time_hours * 236 # formula work out how many calouries user has burnt swimming if swimtype == "2": calb1 = time_hours * 590 if swimtype == "3": calb1 = time_hours * 413 if swimtype == "4": calb1 = time_hours * 590 if swimtype == "5": calb1 = time_hours * 649 print ("on average swimming @ speed of", speed, "mps\nand have burnt", clab1,"calories") # spped , calb1 numbers program calculated score = totaldistance - totaltime # make users score show final 8 score_file.write(str(score)) #this make score string , add score in thye got score file can final 8 later score_file.close() total = (totaldistance, totaltime, speed) swimming_file.write(str(total)) # adds swimming details file , saves string swimming_file.close() score_file = open("score_file","w") # file score added , score calculated users able see final 8 score_file = open("score_file","a") def run():######################## score_file = open("score_file","w") score_file = open("score_file","a") running_file_e = exists("running_file.txt") # if running file exsits open file if running_file_e ==false: # if doesnt exsit create new running file user running_file = open("running_file","w") running_file.close running_file = open("running_file","a") else: running_file = open("running_file","a") totaldistancer = int(input("what total distance ran in km?")) totaltimer = int(input("how long did run in minutes?")) print ("make sure these right values.") totaltimer1 = 60/totaltimer # inputed minuted hours program can accuratly calculate average speed of runner speedr1 = totaldistancer/totaltimer1 calburn = (speedr1 * 95)/(60/totaltimer1) # easy formula amount of calouries runner has burnt can calculated score = totaldistance - totaltime score_file.write(str(score)) score_file.close() print ("the records have been saved") print ("on average running @ speed of", speedr1, "kmph\nyou burnt",calburn," calouries") totalr = (totaldistancer, totaltimer, speedr1, calburn) running_file.write(str(totalr)) running_file.close() def cyc():#################################### score_file = open("score_file","w") score_file = open("score_file","a") cycling_file_file_e = exists("cycling_.txt") if cycling_file_file_e ==false: cycling_file_file = open("cycling_file","w") cycling_file_file.close cycling_file_file = open("cycling_file","a") else: cycling_file = open("cycling_file","a") totaldistancec = int(input("what total distance cycled in km?")) totaltimec = int(input("how long did cycle in minutes?")) print ("make sure these right values. if not pres ctrl z undo mistakes") speedc = totaldistancec/totaltimec if speedc <10: caloriesb= 236 * totaltimec # works out calouries us4er depending on input distance , time if speedc >=10 , speedc <=11.9: caloriesb= 354 * totaltimec if speedc >=12 , speedc <=13.9: caloriesb= 472 * totaltimec if speedc >=14 , speedc <=15.9: caloriesb= 590 * totaltimec if speedc >=16 , speedc <=20: caloriesb= 708 * totaltimec if speedc >20: caloriesb= 944 * totaltimec print ("on average running @ speed of", speedc, "kmph\nyou burnt", caloriesb, " calories") score = totaldistance - totaltime score_file.write(str(score)) score_file.close() totalc = (totaldistancec, totaltimec, speedc) cycling_file.write(str(totalc)) cycling_file.close() personaldetails_file.close() def comp():#################################### username_file = open ("username.txt", "r") username_file.close() which_event = input("which event compare\n1.swimming\n2.cycling\n3.running\n") if which_event == "3": competitor3 = input("who compare data with") n in range (len(ausers)): # finds user first user looking x = n + 1 print (x, ausers[n]) # displays other usres running details person = ausers[(competitor3 - 1)] #calculates actual name of selected user inputted integer run1 = open("running_file","r") # "r" file read line1 = username_file.readlines()# reads whole file content memory run1.close() if which_event == "2": competitor2 = input("who compare data with") n in range (len(ausers)): # "(len" nembered length of users x = n + 1 # python starts counting 0 makes start counting 1 print (x, ausers[n]) person = ausers[(competitor2 - 1)] cyc1 = open("cycling_file","r") line2 = username_file.readlines() cyc1.close() if which_event == "1": competitor1 = input("who compare data with") n in range (len(ausers)): x = n + 1 print (x, ausers[n]) person = ausers[(competitor1 - 1)] swim1 = open("swimming_file","r") line1 = username_file.readlines() swim1.close()
for reason when type 1, 2 or 3 program skips option 4. don't know why. use work while ago cant remember did make skip other functions know why? thank you
Comments
Post a Comment