**Goal: Print out average heights and amount of people are in the file(By counting the names) and ask for new input from user, then calculate the new average height **
Problem: There's no output it just outputs "Process finished with exit code 0" the output should be "Enter Your name : "
Here's the code:
class Calutis:
def init(self):
self.names=[]
self.heights=[]
self.totalheight=0
self.totalcount=0
def reset(self):
self.names = []
self.heights = []
self.totalheight = 0
self.totalcount = 0
def calAvgHeight(self):
f=open("listOfStudentHeight.txt","r")
for line in f:
info=line.split("\t")
self.names.append(info[0])
self.heights.append(float(info[1]))
self.totalheight+=float(info[1])
self.totalcount=len(self.names)
print("the average score of " + self.totalcount + "students is: " + (self.totalheight)/self.totalcount)
def adduser(self):
self.names=input("Enter Your Name : ")
while(True):
try:
self.heights=round(float(input("Enter Your Height in Metres")),2)
break
except ValueError:
print("Enter a valid input for height: ")
try:
self.names=(str(input("Enter Your Name : ")))
break
except ValueError:
print("Enter a valid input for name : ")
f=open("listOfStudentHeight.txt",'a')
f.write(self.names + "\t" + self.heights + "\n")
f.close()
calBox = Calutis()
calBox.adduser()
calBox.calAvgHeight()
This is the weights and names file content:
CHITRA DEVI D/O SILVARAJAH 1.65
MARSHEAL HOUDEL S/O MATHEWS JA 1.72
MUHAMMAD AZLIE B ZULKIFLIE 1.68
HO QIN YUAN Melvin 1.69
TENG YONG PENG DESMOND 1.76
CHEONG LEE YEE 1.59
MUHAMMAD ZULFIKAR B ZAINAL 1.9
ASYRAFIZWANI BTE ABDUL LATIFF 1.58
HIE BAO XIN 1.63
MAK YU JIE 1.67
Please consider lending me a helping hand, Any help will be greatly appreciated !