I want to figure out how to print the result of my code below not in the terminal like it currently does, but change it to create a new file: output.dat and have the results printed in there. Is this possible, and if so how can I amend my code to do this? I'm a beginner btw.
from random import randint
import os
b = {}
for i in range(1000000):
num = randint(1, 50)
if num not in b:
b[num] = 0
b[num] += 1
print ("")
for i in range(1, 51):
print ("Number " +str(i) + ", " + str(b[i]) + "")