diff --git a/Dieters.py b/Dieters.py new file mode 100644 index 0000000..4a428a8 --- /dev/null +++ b/Dieters.py @@ -0,0 +1,19 @@ +input = open('Dieters.txt', 'r') +output = open('Weightloss.txt', 'w') + +num_people = 0 +total_weight = 0 + +name = input.readline().rstrip('\n') +while name != "": + num_people += 1 + start_weight = int(input.readline().rstrip('\n')) + end_weight = int(input.readline().rstrip('\n')) + net_weight = start_weight - end_weight + output.write(name + " lost " + str(net_weight) + " pounds." + '\n') + total_weight += net_weight + name = input.readline().rstrip('\n') + +print("The " + str(num_people) + " people dieting lost a total of " + str(total_weight) + " pounds.") +input.close() +output.close() diff --git a/Dieters.txt b/Dieters.txt new file mode 100644 index 0000000..770eaaa --- /dev/null +++ b/Dieters.txt @@ -0,0 +1,6 @@ +Mary Lou +167 +143 +John +253 +217 \ No newline at end of file diff --git a/Student_Names.py b/Student_Names.py index c6bf448..5f661ed 100644 --- a/Student_Names.py +++ b/Student_Names.py @@ -1,8 +1,10 @@ s = open('studentnames.txt', 'r') -print(s.readline().rstrip('\n')) -print(s.readline().rstrip('\n')) -print(s.readline().rstrip('\n')) -print(s.readline().rstrip('\n')) -print(s.readline().rstrip('\n')) -print(s.readline().rstrip('\n')) -s.close() \ No newline at end of file +i = 0 +for newLine in s: + name = newLine.rstrip('\n') + if name == "": + continue + i += 1 + print("Student " + str(i) + ": " + name) +s.close() +print("There were " + str(i) + " students in the file.") \ No newline at end of file diff --git a/TryAppend.txt b/TryAppend.txt index edc65a4..db3bab5 100644 --- a/TryAppend.txt +++ b/TryAppend.txt @@ -2,3 +2,4 @@ 2022-09-07 16:11:09.535780 2022-09-07 17:11:12.508324 2022-09-07 18:38:19.467371 +2023-01-24 17:53:40.182346 diff --git a/Weightloss.txt b/Weightloss.txt new file mode 100644 index 0000000..89043a7 --- /dev/null +++ b/Weightloss.txt @@ -0,0 +1,2 @@ +Mary Lou lost 24 pounds. +John lost 36 pounds.