Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 0 additions & 102 deletions app.py
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')
Copy link
Collaborator

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



students = {
"Halit": 9,
"Fatma": 7,
"Tas": 8,
"Osman": 8,
"Altom": 7,
"Laetitia": 7,
"Nawal": 9,
"Tinta": 8,
"Erol": 6,
"Orhan": 5
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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]:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
If you want to check range
you can write
grade not in range(1,11)

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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):

Copy link
Collaborator

Choose a reason for hiding this comment

The 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]:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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')
13 changes: 13 additions & 0 deletions worksheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

class Person:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()