assignment 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. def register_student():
  2. student = {
  3. "name": "Paul",
  4. "age": 20,
  5. "course": "Computer Science"
  6. }
  7. print("Registered student:", student)
  8. register_student()
  9. {
  10. "name": "Paul",
  11. "age": 20,
  12. "course": "Computer Science"
  13. }
  14. #PAYROLL CALCULATOR
  15. def calculate_salary():
  16. employee_name = "Paul"
  17. hours_worked = 40
  18. hourly_rate = 20000
  19. tax_rate = 0.10
  20. gross_salary = hours_worked * hourly_rate
  21. tax = gross_salary * tax_rate
  22. net_salary = gross_salary - tax
  23. print("Employee:", employee_name)
  24. print("Gross salary:", gross_salary)
  25. print("Tax:", tax)
  26. print("Net salary:", net_salary)
  27. calculate_salary()
  28. {
  29. "employee_name": "Paul",
  30. "hours_worked": 40,
  31. "hourly_rate": 20000,
  32. "tax_rate": 0.10,
  33. "gross_salary": 800000,
  34. "tax": 80000,
  35. "net_salary": 720000,
  36. }
  37. #POSITIONAL VS KEYWORD ARGUMENTS
  38. def book_flight(passenger_name, destination, seat_class):
  39. print("Booking flight for", passenger_name)
  40. print("Destination:", destination)
  41. print("Seat class:", seat_class)
  42. book_flight("Paul", "Lisbon", "Business")
  43. book_flight(
  44. destination="Lisbon",
  45. passenger_name="Paul",
  46. seat_class="Business"
  47. )
  48. #LOCAL AND GLOBAL VARIABLES
  49. #GLOBAL VARIABLE
  50. school= "Coding time"
  51. def display_school():
  52. print(school)
  53. #local variable
  54. teacher= "Paul"
  55. def display_teacher():
  56. print(teacher)
  57. #DICTIONARY TO JSON
  58. import json
  59. student = {
  60. "name": "Paul",
  61. "age": 20,
  62. "course": "Computer Science"
  63. }
  64. student_json = json.dumps(student)
  65. print(student_json)
  66. #STUDENT MANAGEMENT SYSTEM
  67. import json
  68. students = {
  69. "name": "Yobra",
  70. "age": 20,
  71. "course": "Computer Science"
  72. },
  73. {
  74. "name": "Isaki",
  75. "age": 22,
  76. "course": "Information Technology"
  77. },
  78. {
  79. "name": "Nicole",
  80. "age": 17,
  81. "course": "Business Administration"
  82. }
  83. json_data = json.dumps(students, indent=4)
  84. print("Students data in JSON format:", json_data)