#🔒 Need help to correct my python script
66 messages · Page 1 of 1 (latest)
@sterile pollen
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Could you please send it as codeblock?
how
you shouldnt do call to super class like this
Use three of these ` at the beginning and end
from abc import ABC, abstractmethod
class Personne(ABC):
def __init__(self, nom, prenom, adresse):
self.nom = nom
self.prenom = prenom
self.adresse = adresse
@abstractmethod
def question(self):
self.nom = input("Veuillez encoder le NOM de la personne 😊
self.prenom = input("Veuillez encoder le PRÉNOM de la personne 😊
self.adresse = input("Veuillez encoder l'ADRESSE de la personne 😊
return self.nom, self.prenom, self.adresse
class Employe(Personne):
def init(self, nom, prenom, adresse, fonction):
self.fonction = fonction
super().init(nom)
super().init(prenom)
super().init(adresse)
def questionEmploye(self):
self.fonction = input("Veuillez encoder la FONCTION de l'employé' 😊
return self.fonction
class Eleve(Personne):
def init(self, matricule):
self.matricule = matricule
def questionEleve(self):
self.matricule = input("Veuillez encoder le matricule de l'élève' 😊
return self.matricule
#Main execution
entree = input("Si vous désirez encoder un EMPLOYÉ tapez: 1 \nSivous désirez encoder un ÉLÈVE tapez: 2 \nSi vous désirez quitter le programme tapez: 0 \n")
if int(entree) == 1:
monEmploye = Employe
if int(entree) == 2:
monEleve = Eleve
if entree == 0:
quit
super().__init__(nom, prenom, adresse)
and your eleve class is missing init call to superclass
wdym
You should also call
super().__init__(nom, prenom, adresse)
in your eleve class's __init__
done
Note that abstract method should not have an implementation.
so your Person's question method should either have no implementation, or not be marked with the abstractmethod decorator
In this exercise I must make use of abstract method
Your code needs some restructuration then
from abc import ABC, abstractmethod
class Person(ABC):
def __init__(self):
self.name = input("Enter your name: ")
self.last_name = input("Enter your last name: ")
self.address = input("Enter your address: ")
@abstractmethod
def question(self):
pass
class Employee(Person):
def __init__(self):
super().__init__()
self.function = None
def question(self):
self.function = input("Enter your function: ")
Here's a structure that may fit your needs
I'm sorry I have to go
hope it helps
If you group common data into a class, the class must be abstract. You can force the error linked to the abstraction of the class by annotating for example the str() method using the appropriate annotation.
here is the consign
thank a lot already
from abc import ABC, abstractmethod
class Person(ABC):
def init(self):
self.nom = input("Veuillez encoder le NOM de la personne ")
self.prenom = input("Veuillez encoder le PRÉNOM de la personne ")
self.adresse = input("Veuillez encoder l' ADRESSE de la personne ")
@abstractmethod
def question(self):
pass
class Employe(Person):
def init(self):
super().init()
self.fonction = None
def question(self):
self.fonction = input("Veuillez encoder la FONCTION de la personne ")
class Eleve(Person):
def init(self):
super().init()
self.matricule = None
def question(self):
self.matricule = input("Veuillez encoder le MATRICULE de la personne ")
#Main execution
entree = input("Si vous désirez encoder un EMPLOYÉ tapez: 1 \nSivous désirez encoder un ÉLÈVE tapez: 2 \nSi vous désirez quitter le programme tapez: 0 \n")
if int(entree) == 1:
monEmploye = Employe
if int(entree) == 2:
monEleve = Eleve
if entree == 0:
quit
here is the script after modifications
seems ok
does it work as you expect?
it didn't :'c
Here is the consign of my test
CONTEXT
You work within a training establishment and, in order to facilitate the management of people attending the establishment, you are asked to create a small on-the-go application allowing the coding of both members of the establishment's staff and coding of students attending it.
An employee is characterized by: his last name, his first name, his address and the position he occupies within the establishment.
A student, for his part, is characterized by his name, his first name, his address, his student number generally made up of the first 2 letters of his first name, the first 2 letters of his last name and of 4 digits and the list of courses he attends within the establishment.
The interface, although minimalist, should be easy to use. It must ask the user if they want to encode an employee (1) or a student (2) or exit the program (0).
Once the choice is made. This must request the encoding of all the characteristics specific to the person to be encoded: surname, first name, address, function / surname, first name, address, registration number.
In the case of encoding a student, once all the personal data has been filled in, the program will ask you if you want to add courses to this student.
Finally, when the user decides to leave the program, it will display all the information of the different people encoded during the encoding session.
(used google traduction)
Could you please repost your code in code fences (```py starting line and ``` ending line)? Without these a lot of formatting is lost, particularly underscores.
```py
paste your
code between these lines
```
!code
Can you detail some of the ways that it did not work as expected?
^^ super represents the class youre subclassing from
please on god do not write your code in another language
theres a reason why all languages are english
The OP's code is in English - that's Python's keywords.
It's pretty clear what the rest of the text in the prompts is for.
It's for my test, it's why it's like that :'c
stupid teachers
We have many visitors here who are not working in English, nor should they need to. They make a huge effort to communicate with us here in English, a second language for them.
same
english is my second languages which means i can throw bs like this ^^
Yeah, cultural imperialism. An accident of there computation took off.
I made a somewhat corrected version of what you have sent which I annotated with comments etc if you're interested
Well I salute you. I don't have a second language (a tiny amount of school French).
REALLY
it changed :" to 😊 💀
you will go haven
haven
it doesnt meet all your teachers requirements, still requires you to write a little bit of code
non english code smh
heaven*
does it exist though
thx you man
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
I'd recommend you take a look at the comments I've put and also work on the TODOs
I am checking, huge thanks already man
You're welcome. Happy to help!
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.