Q1: Write a Python code (module) that contains a public variable called counter
, which is initialized to 0. Implement an if-else statement that checks if the code is being run as the main program or if it is being imported as a module into another program. If it is the main program, the code should print "I prefer to be a module.
" If it is being imported as a module, it should print "I like to be a module.
"
# module_example.py
counter = 0
if __name__ == "__main__":
print("I prefer to be a module.")
else:
print("I like to be a module.")