Ejemplo n.º 1
0
from cs50 import get_string
from student import Student

# Space for Students
students = []

# Prompt for students name and dorms
for i in range(3):
    name = get_string('Name: ')
    dorm = get_string('Dorm: ')
    students.append(Student(name, dorm))
# Print students name and dorm

for student in students:
    print(f"{student.name} lives in {student.dorm}.")
Ejemplo n.º 2
0
f.close()

# 从文件中读取将数据转化成对象
f2 = open('a.txt', 'rb')
d2 = pickle.load(f2)
f2.close()
print(d2)

# 将对象转化成json字符串
d3 = dict(name="lisi", age=34, score=90)
jsonStr = json.dumps(d3)
print(jsonStr)

# 将json字符串转化成对像
json_str = '{"age": 20, "score": 88, "name": "Bob"}'
json.loads(json_str)
print("d4 {0}".format(json_str))

# 将Student对象转化成dict
# student=Student('haha',34,90)
# strStudent=json.dumps(student,default=student.student2dict())
# print("Student2Dict {0}".format(strStudent))
#
# json_str = '{"age": 20, "score": 88, "name": "Bob"}'
# print(json.loads(json_str, object_hook=d))

student = Student('haha', 34, 90)
print("Obj2Dict {0}".format(jsonpickle.encode(student)))
json_str = '{"age": 20, "score": 88, "name": "Bob"}'
print("Dict2Obj {0}".format(jsonpickle.decode(json_str)))
Ejemplo n.º 3
0
# classes and objects in python are extremely useful and can help
# make ur code more organized and powerful.

# alot of times when we 're writing programs, we 're gonna have
# to work with differetn types of data and we have all sorts
# of structures we can use to store that data, like lists,
# dictionaries etc.

# however in the real world, not all kind of data can be
# stored in a string or numbers.

# think of it like this, you can't represent a user of
# ur app or even a person with numbers and strings alone.

# classes and objects allows us to create our own data-types

# A class is a blueprint for objects.

# let's model a university student

from student import Student

student1 = Student("Maoti", "50.0", "Science of Fraud", True)
student2 = Student("Maoti", "50.0", "Science of Fraud", True)
student3 = Student("Yinka", "50.0", "Science of Assasination", False)
student4 = Student("Tosin", "50.0", "Science of Talking", True)
student5 = Student("Fawaz", "50.0", "Science of checking temperature", True)

print(student1.gpa)
Ejemplo n.º 4
0
from cs50 import get_string
from student import Student

students = []
# dorms = [] # rather than storing user inputs in two diff arrays, create a struct

for i in range(3):
    name = get_string('name: ')
    dorm = get_string('dorm: ')
    # students.append(name)

    s = Student(name, dorm)
    students.append(s)

    # print(students) # returns mem loc

for student in students:
    print(f'{student.name} lives in {student.dorm}')
Ejemplo n.º 5
0
 def test_get_first_name(self):
     student = Student("Test_First", "Test_Last", "A12345678", True,
                       [10.0, 10.0, 10.0])
     self.assertEqual("Test_First", student.get_first_name())
Ejemplo n.º 6
0
from student import Student
from school import School

exampleStudent1 = Student("Mike", "Biology", 3.5)
exampleStudent2 = Student("Jim", "Mathematics", 4.0)
exampleStudent3 = Student("Catherine", "Computer Science", 2.7)
exampleStudent4 = Student("Joseph", "Law", 2.2)
exampleStudent5 = Student("Angel", "Environmental Sciences", 3.2)

exampleSchool = School("Example University", "Somewhere, Wisconsin", [
    exampleStudent1, exampleStudent2, exampleStudent3, exampleStudent4,
    exampleStudent5
])

exampleSchool.get_school_details()
exampleSchool.get_all_student_descriptions()
Ejemplo n.º 7
0
from student import Student

stud1 = Student("John", 20, "Male", 70, 75, 73, 65, 68)
stud1.total()
stud1.average()
print(stud1.average)

stud2 = Student("Mary", 25, "female", 70, 75, 73, 65, 68)
stud2.total()
print(stud2.total)
Ejemplo n.º 8
0
# TODO
############

exit_value = 1
try:
    the_server = Server(questions='Questions/regtest', name=name)
    tests = sorted(globals())
    if len(sys.argv) > 1:
        tests = [t for t in tests if t in sys.argv]
    for test in tests:
        if not test.startswith('test_'):
            continue
        print('%-45s' % test, end=' ')
        sys.stdout.flush()
        if '_root_' in test:
            roles = "['Default','Teacher','Author','Grader','Developer','Admin']"
        else:
            roles = "['Student']"
        globals()[test](Student(
            the_server,
            test[len('test_'):],
            roles=roles,
        ))
        print('OK')
    print('All tests are fine')
    exit_value = 0
finally:
    the_server.stop()

sys.exit(exit_value)
Ejemplo n.º 9
0
def test_0340_relog(student):
    student.expect('<A class="content tips" href="?session_deconnection=1">')
    student = Student(the_server, student.name)
    student.expect('<A class="content tips" href="?session_deconnection=1">')
Ejemplo n.º 10
0
from student import Student

# Create at least 10 students

s1 = Student('Kevin', 'Chiteri')
s2 = Student('Allan', 'M.', 'UG')

# Make at least 5 students attend class

# e.g
s1.attend_class(...)

# You should be able to print the list of
# students who attend class on particular day
 def find(self, id):
     self.__data = self.getAllD()
     for student in self.__data:
         if student.getId() == id:
             return Student(id, student.getName())
Ejemplo n.º 12
0
import csv
import mysql.connector
from student import Student
#import ipdb; ipdb.set_trace()
koko = 0   
list = []
with open('students.csv','r') as csvFile:
    reader = csv.DictReader(csvFile)
  
    for row in reader:
        list.append(Student(**row)) 
        print(list)


            



csvFile.close()
    


#a , b , c , d , e = input('enter your firstname, lastname, phone, address, and major , while seperating each entity with 1 space\n').split()
#p1 = Student(a,b,c,d,e)
#p1.register()
Ejemplo n.º 13
0
from student import Student
from instructor import Instructor
from cohort import Cohort
from exercise import Exercise

exercise1 = Exercise("High", "CSS") 
exercise2 = Exercise("Low", "HTML") 
exercise3 = Exercise("Mid", "JavaScript") 
exercise4 = Exercise("Expert", "Python") 

cohort1 = Cohort("Cohort 101")
cohort2 = Cohort("Cohort 100")
cohort3 = Cohort("Cohort 99")

student1 = Student("Slim", "Pickens", "SlimPick", "Cohort 100")
student2 = Student("Luke", "Jackson", "LJ", "Cohort 99")
student3 = Student("Martin", "Riggs", "Lethal_Weapon", "Cohort 101")
student4 = Student("Roger", "Murtaugh", "Too_Old", "Cohort 101")

instructor1 = Instructor("Jisie", "David", "JD", "Cohort 101", "JavaScript")
instructor2 = Instructor("Chase", "Fite", "CF", "Cohort 100", "Python")
instructor3 = Instructor("Kristen", "Norris", "KN", "Cohort 99", "HTML")

instructor1.assign(student3, exercise1)
instructor1.assign(student3, exercise2)
instructor1.assign(student4, exercise1)
instructor1.assign(student4, exercise2)
instructor2.assign(student1, exercise3)
instructor2.assign(student1, exercise4)
instructor3.assign(student2, exercise1)
instructor3.assign(student2, exercise4)
Ejemplo n.º 14
0
    def __init__(self):
        pygame.init()
        self.screen = pygame.display.set_mode(SIZE_OF_WINDOW)
        self.background_image = pygame.image.load(
            'images/backgrounds/main_background.png')
        self.buttons_background = pygame.image.load(
            'images/backgrounds/buttons_back.png')
        self.clock = pygame.time.Clock()
        self.objects = []
        self.gamer = Student(
            x=620,
            y=542,
            width=250,
            height=390,
            name='Bob',
            image='images/student_male.png',
            name_background='images/backgrounds/name_back.png',
            surface=self.screen,
            name_x=20,
            name_y=230)

        self.button_alcohol = Button(x=149,
                                     y=646,
                                     width=90,
                                     height=90,
                                     image='images/buttons/drink_button.png',
                                     characteristic='alcohol',
                                     surface=self.screen)
        self.button_health = Button(x=257,
                                    y=646,
                                    width=90,
                                    height=90,
                                    image='images/buttons/eat_button.png',
                                    characteristic='health',
                                    surface=self.screen)
        self.button_grades = GradesButton(
            x=365,
            y=646,
            width=90,
            height=90,
            image='images/buttons/study_button.png',
            characteristic='grades',
            surface=self.screen)
        self.button_money = Button(x=473,
                                   y=646,
                                   width=90,
                                   height=90,
                                   image='images/buttons/money_button.png',
                                   characteristic='money',
                                   surface=self.screen)
        self.button_fatigue = Button(x=582,
                                     y=646,
                                     width=90,
                                     height=90,
                                     image='images/buttons/sleep_button.png',
                                     characteristic='fatigue',
                                     surface=self.screen)

        self.statusbar_alcohol = StatusBar(
            x=20,
            y=10,
            width=290,
            height=65,
            txt_color=WHITE,
            value=self.gamer.statistics['alcohol'],
            surface=self.screen,
            background='images/backgrounds/alcohol_back.png',
            characteristic='alcohol')
        self.statusbar_health = StatusBar(
            x=20,
            y=85,
            width=290,
            height=65,
            txt_color=WHITE,
            value=self.gamer.statistics['health'],
            surface=self.screen,
            background='images/backgrounds/health_back.png',
            characteristic='health')
        self.statusbar_grades = StatusBar(
            x=20,
            y=160,
            width=290,
            height=65,
            txt_color=WHITE,
            value=self.gamer.statistics['grades'],
            surface=self.screen,
            background='images/backgrounds/grades_back.png',
            characteristic='grades')
        self.statusbar_money = StatusBar(
            x=330,
            y=10,
            width=290,
            height=65,
            txt_color=WHITE,
            value=self.gamer.statistics['money'],
            surface=self.screen,
            background='images/backgrounds/money_back.png',
            characteristic='money')
        self.statusbar_fatigue = StatusBar(
            x=330,
            y=85,
            width=290,
            height=65,
            txt_color=WHITE,
            value=self.gamer.statistics['fatigue'],
            surface=self.screen,
            background='images/backgrounds/fatigue_back.png',
            characteristic='fatigue')

        self.timer = Timer(x=150,
                           y=310,
                           width=120,
                           height=90,
                           surface=self.screen,
                           txt_color=(0, 0, 0),
                           value=0,
                           background='images/calendar.png')  # ADDED
        self.clocks = Clocks(0, datetime.datetime.now(), 0)
        self.gameover = InfoGameover(x=250,
                                     y=160,
                                     width=550,
                                     height=550,
                                     color=(255, 255, 255),
                                     txt_color=(0, 0, 0),
                                     value=0,
                                     gamer=self.gamer,
                                     clocks=self.clocks,
                                     screen=self.screen,
                                     size_of_window=SIZE_OF_WINDOW)
        self.menu = Menu(x=0,
                         y=0,
                         width=SIZE_OF_WINDOW[0],
                         height=SIZE_OF_WINDOW[1],
                         text_color=(25, 25, 25),
                         color=(243, 243, 243, 140),
                         screen=self.screen,
                         clocks=self.clocks)
        self.health_event = RandomEventHealth(x=250,
                                              y=160,
                                              width=550,
                                              height=550,
                                              screen=self.screen,
                                              days=self.clocks,
                                              gamer=self.gamer,
                                              size_of_window=SIZE_OF_WINDOW)
        self.save = Save()
        self.HEALTH_DECREASE = pygame.USEREVENT  # TODO сделать эти переменные через список
        self.FATIGUE_DECREASE = pygame.USEREVENT + 1
        self.MONEY_DECREASE = pygame.USEREVENT + 2
        self.ALCOHOL_DECREASE = pygame.USEREVENT + 3
        self.GRADES = pygame.USEREVENT + 4
Ejemplo n.º 15
0
 def test_80_to_100(self):
     s1 = Student('Bart', 80)
     s2 = Student('Lisa', 100)
     self.assertEqual(s1.get_grade(), 'A')
     self.assertEqual(s2.get_grade(), 'A')
Ejemplo n.º 16
0
def test_0350_logout(student):
    student.expect('<A class="content tips" href="?session_deconnection=1">')
    student.get('?session_deconnection=1')
    student.expect('<script>window.location=')
    student = Student(the_server, student.name)
    student.expect('<A class="content tips" href="?session_deconnection=1">')
Ejemplo n.º 17
0
def sendNewStudent():
    url = 'http://localhost:5000/todo/api/v1.0/students'
    obj = Student("fred", 12, 1.4)
    stu = {"student": {"name": "kika", "age": 12}, "year": 1, "clas": 2}
    student = json.load(stu)
    return requests.post(url, data=student).json()
Ejemplo n.º 18
0
## ZeroDivisionError and ValueError are for specific errors
    
####################################################
################  Modules & Pip  ########### 
import usefultools

print(usefultools.roll_dice(10))


####################################################
################  Class and objects   ########### 
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")    
#creating our own data type
from student import Student

student1 = Student("Jim", "Business", 3.1, False)
student2 = Student("Pam", "Art", 5, True)

print(student2.gpa)    
    
####################################################
################  Question quiz  ###########     
    
from question import Question

##creating the array of question prompts
question_prompts = [
    "what color are apples?\n (a) Red\n (b) Orange\n what's your answer?\n",
    "what color are Bananas?\n (a) Red\n (b) Yellow\n what's your answer?\n",  
    "what color are strawberries?\n (a) Red\n (b) Orange\n what's your answer?\n"
    ]#问题提示
Ejemplo n.º 19
0
            print('文件中没有这个学号的学生')
        else:
            print(s)
    elif choice == '3':
        b.SortByScore()
        b.ShowStudent()
    elif choice == '4':
        b.SortByAge()
        b.ShowStudent()
    elif choice == '5':
        print('请输入学生的个人信息:')
        id = int(input('学号:'))
        name = input('姓名:')
        score = int(input('成绩:'))
        age = int(input('年龄:'))
        student = Student(id, name, score, age)
        r = b.AddStudent(student)
        print(r)
    elif choice == '6':
        id = int(input('请输入需要删除学生的学号:'))
        r = b.DeleteStudent(id)
        print(r)

    elif choice == '7':
        id = int(input('请输入需要修改学生的学号:'))
        r = b.UpdateStudent(id)
        print(r)

    elif choice == '9':
        b.SaveData()
        print('保存信息到student.txt成功!')
Ejemplo n.º 20
0
from cohort import Cohort
from instructor import Instructor

#create exercises
exercise1 = Exercise("do something", "python")
exercise2 = Exercise("do anything", "python")
exercise3 = Exercise("make something", "python")
exercise4 = Exercise("make anything", "python")

#create cohorts
cohort36 = Cohort("Cohort 36")
cohort35 = Cohort("Cohort 35")
cohort37 = Cohort("Cohort 37")

#create students
ryan1 = Student("Ryan", "Cunningham", "rc1")
ryan2 = Student("Ryan", "Bishop", "rb1")
ryan3 = Student("Ryan", "Crawley", "rc2")
sullivan = Student("Sully", "Pierce", "sp1")

#assign students
cohort36.add_student(ryan1)
cohort36.add_student(ryan2)
cohort36.add_student(ryan3)
cohort36.add_student(sullivan)

#create instructors
joe = Instructor("Joe", "Shepherd", "js1", "funny")
jisie = Instructor("Jisie", "David", "jd1", "good at instructing")
jenna = Instructor("Jenna", "not sure", "jn1", "teaching")
Ejemplo n.º 21
0
from student import Student

sdnt1 = Student("Meikä", "Manne", "tvt18")
sdnt2 = Student("Daniel", "Manninen", "kto17")
sdnt3 = Student("Valtsu", "Kirsula", "kto16")
sdnt4 = Student("Arttu", "Heikkinen", "tvt18")
sdnt5 = Student("Ollo", "Simp", "tvt17")
sdnt6 = Student("Agile", "Jondo", "kto19")

list = [sdnt1, sdnt2, sdnt3, sdnt4, sdnt5, sdnt6]

for obj in list:
    print(obj.info())
Ejemplo n.º 22
0
import os
from flask import Flask, request, jsonify, render_template, Response
from student import Student

# Initialization
app = Flask(__name__)
# app.debug = True

students = {s.id: s for s in [
    Student("Patricio Lopez", "MrPatiwi", True),
    Student("Jaime Castro", "jecastro1", False),
    Student("Belen Saldias", "bcsaldias", False)
]}


def param_to_bool(data):
    return data is not None and data.lower() == 'true'


# Controllers
@app.route("/")
def index():
    return render_template('index.html')


@app.route("/students", methods=['GET', 'POST'])
def students_index():
    if request.method == 'GET':
        items = [s.serialize() for (identifier, s) in students.items()]
        return jsonify(students=items), 200
Ejemplo n.º 23
0
from people import People
from student import Student

peo = People('raj', 1)

stu = Student('tim', 2, '三年级')

peo.speak()

stu.speak()

import requests

requests.get('')

Ejemplo n.º 24
0
from student import Student
from teacher import Teacher

student = Student()
teacher = Teacher()

student.question(teacher)
teacher.teach(student)
Ejemplo n.º 25
0
from student import Student

tim = Student("Tim")
lisa = Student("Lisa")

tim.addGrade('A')
tim.addGrade('B')
tim.addGrade('B')
tim.addGrade('A')

tim.addGrade('E')
tim.addGrade('P')

lisa.addGrade('C')
lisa.addGrade('B')
lisa.addGrade('A')
lisa.addGrade('A')
lisa.addGrade('A')
lisa.addGrade('A')

print("{0}'s GPA is: {1}".format(tim.getName(), tim.getGpa()))
print("{0}'s GPA is: {1}".format(lisa.getName(), lisa.getGpa()))
Ejemplo n.º 26
0
 def test_60_to_80(self):
     s1 = Student('Bart', 60)
     s2 = Student('Lisa', 79)
     self.assertEqual(s1.get_grade(), 'B')
     self.assertEqual(s2.get_grade(), 'B')
Ejemplo n.º 27
0
                              password='******',
                              host='127.0.0.1',
                              database='bootcamp')

cursor = cnx.cursor()

query_for_students = ("select * from students")

query_for_courses = ("select * from course")

cursor.execute(query_for_students)

students = []

for student in cursor:
    s = Student(student[1], student[2], student[3])
    students.append(s)

cursor.execute(query_for_courses)

courses = []

for cc in cursor:
    c = Course(cc[1], cc[2])
    courses.append(c)

for s in students:
    print('Soyadı: %s | Adı: %s | Yaşı: %d' % (s.surname, s.name, s.age()))

for c in courses:
    print('Adı: %s | Adresi: %s' % (c.name, c.address))
Ejemplo n.º 28
0
 def test_0_to_60(self):
     s1 = Student('Bart', 0)
     s2 = Student('Lisa', 59)
     self.assertEqual(s1.get_grade(), 'C')
     self.assertEqual(s2.get_grade(), 'C')
Ejemplo n.º 29
0
# 1. Data entry
# <Name> <Class1> <Grade1> <Class2> <Grade2> ...
# add the student and his grades to a data structure that
# can be accessed later

# 2. Data access
# <Name> <Class>
# Student <Name> has a grade of <Grade> in <Class>

# 3. quit
my_dict = {}

while True:
    command = input("What do you want to do to your grades?")
    args = command.split()
    if len(args) > 2:
        name = args[0]
        args.pop(0)
        if (name not in my_dict):
            my_dict[name] = Student(name)
        for i in range(0, len(args), 2):
            class_name = args[i]
            grade = args[i + 1]
            my_dict[name].setGrade(class_name, grade)
    elif len(args) == 2:
        name = args[0]
        class_name = args[1]
        my_dict[name].printGrade(class_name)
    elif args[0] == "quit":
        break
Ejemplo n.º 30
0
 def test_set_status_reflects_argument_passed(self):
     mock_student = Student("Jenny", "Kramer", "A42154852", True, 89, 76)
     mock_student.set_status(False)
     self.assertEqual(mock_student.get_status(), False)