Advertisement
Adehumble

Week8|9 Coding Exercise 5

Apr 1st, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #5
  2. #This program demonstrates how to use a namedtuple to creates a class.
  3.  
  4. import collections as collect
  5. import time
  6.  
  7. #This will creates a class
  8. GymExercise=collect.namedtuple("GymExercise", ["name", "weight", "reps"])
  9.  
  10. #The following lines represents GymExercise class created objects
  11.  
  12. squat=GymExercise(reps=3, weight=265, name="squat")
  13.  
  14. bench=GymExercise(name="benchpress",weight=185,reps=5)
  15.  
  16. deadlift=GymExercise("deadlift", reps=6, weight= 225)
  17.  
  18. press=GymExercise("press",120,8)
  19.  
  20.  
  21.  
  22. #If uncommented, the following print statements would validate that the above codes will run seamlessly without errors
  23.  
  24. #print(squat.weight)
  25. #print(bench.name)
  26. #print(deadlift.name)
  27. #print(press.reps)
  28.  
  29. time.sleep(5) #This will end the program only after 5second.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement