from operator import call
from psutil import cpu_count, cpu_freq, cpu_percent, virtual_memory
funcs = {
'cpuspeed': lambda: f"The CPU speed is {cpu_freq([1])[0][0]:,} MHz.",
'cores': lambda: f"This CPU has {cpu_count(False):,} cores and {cpu_count():,} threads.",
'cpu': lambda: f"Current CPU usage is {cpu_percent():,}%.",
'ram': lambda: f"There is {round(virtual_memory()[1] / 1024 ** 2):,} MB of available RAM."
}
combined_funcs = lambda: '\n'.join(call(func) for func in funcs.values())
try:
while True:
func_to_call = funcs.get(input("Please type 'cpu', 'ram', 'cores', 'cpuspeed' or press ENTER to show all stats: "), combined_funcs)
print(call(func_to_call))
except KeyboardInterrupt:
print("Exiting…")