I am trying to get this to log the options chosen over time, then suggest the one most commonly used. I got the logging part working but the result of printing the max() statement is just a ". any suggestions?
I found a solution!
import json def forecast(): '''Produces a forecast based on barometric pressure trends and logs which trend is choosen.''' while True: options = ['1 Rising', '2 Falling', '3 Steady'] print('\n'.join(options)) trend = input('\nChoose a trend for the barometric pressure.\n> ') logEntry = f'{trend}' with open('useLog.jsn', 'a') as outfile: json.dump(logEntry, outfile) look = open('useLog.jsn').read() print(look) most_common = max(look, key = look.count) print(most_common) # This only prints a ". if trend == '1': print('\nFairer weather on the way.\n') elif trend == '2': print('\nPoorer weather on the way.\n') elif trend == '3': print('\nNo significant change.\n') forecast()
Output:PS C:\Users\new user\desktop> python wtest.py
1 Rising
2 Falling
3 Steady
Choose a trend for the barometric pressure.
> 1
"1""1""1""2""3""4""1""2""3""4""5""1"
"
Fairer weather on the way.
1 Rising
2 Falling
3 Steady
Choose a trend for the barometric pressure.
>
I found a solution!


def forecast(): '''Produces a forecast based on barometric pressure trends and logs which trend is choosen.''' while True: options = ['1 Rising', '2 Falling', '3 Steady'] print('\n'.join(options)) trend = input('\nChoose a trend for the barometric pressure.\n> ') logEntry = f'{trend}' f = open('useLog.txt', 'a') f.write(logEntry) look = open('useLog.txt').read() most_common = max(look, key = look.count) print(f'\n{most_common}') if trend == '1': print('\nFairer weather on the way.\n') elif trend == '2': print('\nPoorer weather on the way.\n') elif trend == '3': print('\nNo significant change.\n') forecast()