| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- def register_student():
- student = {
- "name": "Paul",
- "age": 20,
- "course": "Computer Science"
- }
- print("Registered student:", student)
- register_student()
- {
- "name": "Paul",
- "age": 20,
- "course": "Computer Science"
- }
- #PAYROLL CALCULATOR
- def calculate_salary():
- employee_name = "Paul"
- hours_worked = 40
- hourly_rate = 20000
- tax_rate = 0.10
- gross_salary = hours_worked * hourly_rate
- tax = gross_salary * tax_rate
- net_salary = gross_salary - tax
- print("Employee:", employee_name)
- print("Gross salary:", gross_salary)
- print("Tax:", tax)
- print("Net salary:", net_salary)
- calculate_salary()
- {
- "employee_name": "Paul",
- "hours_worked": 40,
- "hourly_rate": 20000,
- "tax_rate": 0.10,
- "gross_salary": 800000,
- "tax": 80000,
- "net_salary": 720000,
- }
- #POSITIONAL VS KEYWORD ARGUMENTS
- def book_flight(passenger_name, destination, seat_class):
- print("Booking flight for", passenger_name)
- print("Destination:", destination)
- print("Seat class:", seat_class)
- book_flight("Paul", "Lisbon", "Business")
- book_flight(
- destination="Lisbon",
- passenger_name="Paul",
- seat_class="Business"
- )
- #LOCAL AND GLOBAL VARIABLES
- #GLOBAL VARIABLE
- school= "Coding time"
- def display_school():
- print(school)
- #local variable
- teacher= "Paul"
- def display_teacher():
- print(teacher)
- #DICTIONARY TO JSON
- import json
- student = {
- "name": "Paul",
- "age": 20,
- "course": "Computer Science"
- }
- student_json = json.dumps(student)
- print(student_json)
- #STUDENT MANAGEMENT SYSTEM
- import json
- students = {
- "name": "Yobra",
- "age": 20,
- "course": "Computer Science"
- },
- {
- "name": "Isaki",
- "age": 22,
- "course": "Information Technology"
- },
- {
- "name": "Nicole",
- "age": 17,
- "course": "Business Administration"
- }
- json_data = json.dumps(students, indent=4)
- print("Students data in JSON format:", json_data)
|