ssign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of the class 'Student'.
Question
ssign and print the roll number, phone number and address of two students having names "Sam" and "John" respectively by creating two objects of the class 'Student'.
Solution
Sure, here is how you can do it in Python:
First, you need to define the class 'Student'. This class will have attributes for name, roll number, phone number, and address.
class Student:
def __init__(self, name, roll_number, phone_number, address):
self.name = name
self.roll_number = roll_number
self.phone_number = phone_number
self.address = address
Then, you can create two objects of the class 'Student' for "Sam" and "John" respectively.
sam = Student("Sam", "001", "1234567890", "123 Sam St")
john = Student("John", "002", "0987654321", "456 John St")
Finally, you can print the roll number, phone number, and address of Sam and John.
print(f"Sam's details: Roll Number - {sam.roll_number}, Phone Number - {sam.phone_number}, Address - {sam.address}")
print(f"John's details: Roll Number - {john.roll_number}, Phone Number - {john.phone_number}, Address - {john.address}")
This will output:
Sam's details: Roll Number - 001, Phone Number - 1234567890, Address - 123 Sam St
John's details: Roll Number - 002, Phone Number - 0987654321, Address - 456 John St
Similar Questions
Create a class named 'Student' with a string variable 'name' and an integer variable 'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an object of the class Student.
Get a count of number of students. Get the input details from each student like 'name', 'address', ‘class number’ and ‘department’ till that particular count is reached.In the names of the student where the pattern “in” occurs. Replace it by ‘$$’.Using static member functions/static variable, assign a unique roll number to each student.Display all the student details. Implement the above process using java class and constructors.Ex: Stalin (pattern “in”)
Develop a Java program to add student’s names and display it using vectorclass.
DescriptionYou need to create a Constructor function which will create object for Student details of the following properties:name: It will store student nameroll_no: Stores the roll numberclass: Stores the classsection: Stores the sectionmarks_of_5_subjects: It will store marks of science, maths, social science, english & hindi. You can store marks in this format:{ science: 72, maths: 75, social_science: 79, english: 80, hindi: 67}printTop3Subjects: It is a function method. It will print top three subject names based on marks.printReportCard: It is also a function method. It will create and print a report card of a student. For example:+--------------------+| REPORT CARD |+--------------------+| Name - Huzaifa || Roll no. - 16 || Class - X || Section - A || Science - 73 || S.Sc - 79 || Maths - 75 || English - 80 | | Hindi - 67 || Prectage - 74.8 % |+--------------------+
In a school, each student is identified by a unique combination of a class section and a roll number. Write a program that takes input for the class section (either uppercase or lowercase character) and the roll number (an integer). The program should then output a message indicating the student's roll number in the specified class section.Input format :The first line of input is a character c, representing the class section (A-Z or a-z).The second line of input is an integer d, representing the roll number.Output format :The output displays a message indicating the roll number and class section in the format: "Roll number d in Section c".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:1 ≤ d ≤ 50The class section must be a letter in either uppercase or lowercase.Sample test cases :Input 1 :A30Output 1 :Roll number 30 in Section AInput 2 :D50Output 2 :Roll number 50 in Section DInput 3 :z25Output 3 :Roll number 25 in Section z
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.