0
Missing code
Need help with the input code to get the output code: Output: Enter first name: >>> Alex Enter last name: >>> Jones Jones Alex Input: class Student(): def _init_(): self.name = name self.surname = surname print(self.surname) print(self.name) name = input("Enter first name: ") surname = input("Enter last name: ") print(surname) print(name)
3 Antworten
+ 3
In your class your __init__() should have the parameters self, name, surname. Then you pass the input arguments when creating a Student object.
Also, the __init__() method uses double underscores.
class Student():
def __init__(self, name, surname):
self.name = name
self.surname = surname
...
name = input("Enter first name: ")
surname = input("Enter last name: ")
Student alex = Student(name, surname)
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2467/
+ 2
Ashraf Nagy
Please do not write codes into the thread tags. Just put Python there instead to clarify language context 👍
+ 2
You didn't initialize your name variable properly, init requires self argument