-
Notifications
You must be signed in to change notification settings - Fork 0
develop branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +0,0 @@ | ||
|
||
order = False | ||
|
||
entrance = input(''' | ||
Hello, | ||
This app shows CYF Manchester Class Students names and grades | ||
You can see all students by ordering 'show_all' | ||
You can see a student by ordering 'show_one' | ||
You can add a new student by ordering 'add_student' | ||
You can update a student' grade by ordering 'update' | ||
You can get the average of class by 'average_grade' | ||
You can close the app by ordering 'finish' | ||
Would you like to go on ? Yes or No : | ||
''') | ||
|
||
if entrance.lower() == 'yes': | ||
order = True | ||
elif entrance.lower() == 'no': | ||
print('Thank you, see you next time...') | ||
else: | ||
input('Your request is not recognised') | ||
|
||
|
||
students = { | ||
"Halit": 9, | ||
"Fatma": 7, | ||
"Tas": 8, | ||
"Osman": 8, | ||
"Altom": 7, | ||
"Laetitia": 7, | ||
"Nawal": 9, | ||
"Tinta": 8, | ||
"Erol": 6, | ||
"Orhan": 5 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice use of dict |
||
|
||
def show_all(): | ||
print(students) | ||
|
||
|
||
def show_one(name): | ||
print(students.get(name)) | ||
|
||
|
||
def add_student(name,grade): | ||
if name in students: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may need to add some string manipulation, capital case or lower case |
||
print('We already have a student with this name') | ||
return | ||
|
||
if grade not in [1-10]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is tricky, remember all input from user get registered as "String", so you need to cast it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also [] is list in python (similar to Array ) so you have here one item with value -9. |
||
print('Level must be between 1-10') | ||
return | ||
|
||
try: | ||
students[name] = int(grade) | ||
print(f"{name} is added with grade {students.get(name)}") | ||
except ValueError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usually it good to add a general exception JIC |
||
print('Please type a number as a level') | ||
|
||
def update (name, grade): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line is not a good idea in python :) things can get off records quickly here with no () |
||
if grade not in [1 - 10]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. input need casting |
||
print('Level must be between 1-10') | ||
return | ||
try: | ||
students[name] = int(grade) | ||
print(f"{name}'s grade is updated as {students.get(name)}") | ||
except ValueError: | ||
print('Please type a number as a level') | ||
|
||
|
||
def get_avg (): | ||
avg = sum(students.values())/len(students) | ||
print(f'Average grade of class is {avg}') | ||
|
||
def finish (): | ||
global order | ||
order = False | ||
print("Thank You, See you next time") | ||
|
||
reducer = { | ||
'show_all': show_all, | ||
'show_one': show_one, | ||
'add_student':add_student, | ||
'update': update, | ||
'average_grade': get_avg, | ||
'finish': finish | ||
} | ||
|
||
while order: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impressive work on while one! |
||
msg = input('request: ') | ||
my_function = reducer.get(msg, 'error') | ||
if msg == 'show_one': | ||
name = input('name: ') | ||
my_function(name) | ||
elif msg in {'update', 'add_student'}: | ||
name = input('name: ') | ||
grade = input('grade: ') | ||
my_function(name, grade) | ||
elif msg in {'show_all', 'finish', 'average_grade'}: | ||
my_function() | ||
else : print ('Request is not recognised') | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
class Person: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something went wrong here :D |
||
|
||
def __init__(self, name): | ||
self.name=name | ||
|
||
def talk(self): | ||
print(f'Hi, I`m {self.name}') | ||
|
||
|
||
person1=Person('Hakan Zahit') | ||
|
||
person1.talk() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to give an option or command for user to re enter yes or finish