Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook assignments/Week4/Count operations.ipynb

18 views
Kernel: Python 2 (SageMath)
# Functions to manipulate global variable count ################################################### # Student should enter function on the next lines. # Reset global count to zero. # Increment global count. # Decrement global count. # Print global count. def reset(): global count count = 0 return count def increment(): global count count = count + 1 return count def print_count(): global count print count return count def decrement(): global count count = count - 1 return count ################################################### # Test - don't change # note that the GLOBAL count is defined inside a function reset() increment() print_count() increment() print_count() reset() decrement() decrement() print_count() #################################################### # Output #1 #2 #-2
1 2 -2
-2