Monday, July 15, 2019

Global and local variables in functions

Script

#!/usr/local/bin/python3.5

runs = 15921
tests = 173

def tendulkar():
  tests = 200
        print("Number of runs scored by Tendulkar in Tests: ", runs)
        print("Number of Tests played by Tendulkar: ", tests)

def dravid():
  tests = 164
  runs = 13288
  print("Number of runs scored by Dravid in Tests: ", runs)
  print("Number of Tests played by Dravid: ", tests)

def laxman():
  number_of_tests = 134
  number_of_runs = 8781
  print("Number of runs scored by Laxman in Tests: ", runs)
  print("No, that was wrong.  Number of runs scored by Laxman in Tests: ", number_of_runs)
  print("Number of Tests played by Laxman: ", tests)
  print("No, that was wrong.  Number of Tests played by Laxman: ", number_of_tests)

tendulkar()
dravid()
print("\n\n")
laxman()
print()
laxman()
print()
laxman()

Execution

Number of runs scored by Tendulkar in Tests:  15921
Number of Tests played by Tendulkar:  200
Number of runs scored by Dravid in Tests:  13288
Number of Tests played by Dravid:  164



Number of runs scored by Laxman in Tests:  15921
No, that was wrong.  Number of runs scored by Laxman in Tests:  8781
Number of Tests played by Laxman:  173
No, that was wrong.  Number of Tests played by Laxman:  134

Number of runs scored by Laxman in Tests:  15921
No, that was wrong.  Number of runs scored by Laxman in Tests:  8781
Number of Tests played by Laxman:  173
No, that was wrong.  Number of Tests played by Laxman:  134

Number of runs scored by Laxman in Tests:  15921
No, that was wrong.  Number of runs scored by Laxman in Tests:  8781
Number of Tests played by Laxman:  173
No, that was wrong.  Number of Tests played by Laxman:  134





No comments:

Post a Comment