Person Greeting
Programming Interview
Easy
8 views
Problem Description
Name and age are provided. Create class Person with method greet() that returns 'Hi , you are '. Output greet().
Input Format
One line: name age.
Output Format
One line greeting.
Sample Test Case
Output:
Hi Ravi, you are 21
Constraints
Name has no spaces.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if len(p)<2: sys.exit(0)
name=p[0]
age=int(p[1])
class Person:
def __init__(self,name,age):
self.name=name
self.age=age
def greet(self):
return f'Hi {self.name}, you are {self.age}'
print(Person(name,age).greet())
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!