Back

100 days of python Advance assignment code

Created 1 year ago
135 Views
1 Comments
RADHERAMAN
@RADHERAMAN
RADHERAMAN
@RADHERAMANProfile is locked. Login

GUVI --> 100 Days Of Python Advanced

Assignment:

1.

class Calculator:

def add(self, a, b):

return a + b

def subtract(self, a, b):

return a - b

def multiply(self, a, b):

return a * b

def divide(self, a, b):

if b == 0:

raise ValueError("Division by zero is not allowed")

return a / b

a, b = map(int, input().split())

calc = Calculator()

print(calc.add(a, b))

print(calc.subtract(a, b))

print(calc.multiply(a, b))

print(calc.divide(a, b))

2.

import json

def find_matching_people(json_str):

people = json.loads(json_str)

matching_names = [person["name"] for person in people if person["age"] >= 30 and person["nationality"] == "USA"]

if matching_names:

print(" ".join(matching_names))

else:

print("No matching people found")

json_str = input()

find_matching_people(json_str)

Comments
Please login to comment.