Python Home Work
Python Home Work
12
123
1234
12345
Question 2:
Accept number from user and calculate the sum of all number between 1 and given
number
Question 3:
Given a list iterate it and display numbers which are divisible by 5 and if you find
number greater than 150 stop the loop iteration
list1 = [12, 15, 32, 42, 55, 75, 122, 132, 150, 180, 200]
Question 4:
Expected Output:
[4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]
Question 5:
Question 6:
Expected output:
Question 7:
Expected output:
Question 8:
Given:
str1 = "Emma is a data scientist who knows Python. Emma works at google."
Expected Output:
exercise 9:
Given a Python dictionary, Change Brad’s salary to 8500
sampleDict = {
'emp1': {'name': 'Jhon', 'salary': 7500},
'emp2': {'name': 'Emma', 'salary': 8000},
'emp3': {'name': 'Brad', 'salary': 6500}
}
Expected output:
sampleDict = {
'emp1': {'name': 'Jhon', 'salary': 7500},
'emp2': {'name': 'Emma', 'salary': 8000},
'emp3': {'name': 'Brad', 'salary': 8500}
}
OOP PROBLEMS
Small project
Requirements
Each Student has a reason for attending Codebar (e.g., "I've always wanted to
make websites!").
Each Instructor a bio (e.g., "I've been coding in Python for 5 years and want to
share the love!").
Each Instructor also has a set of skills (e.g., ["Python", "Javascript", "C++"]).
An Instructor can gain a new skill using add_skill.
A date.
A subject.
A group of instructors.
A roster of students.
An add_participant method that accepts a member as an argument. If the
Member is an Instructor, add them to the instructors list. If a Member is a
Student, add them to the students list.
Create another method print_details that outputs the details of the workshop.
jane = Student("Jane Doe", "I am trying to learn programming and need some
help")
lena = Student("Lena Smith", "I am really excited about learning to
program!")
vicky = Instructor("Vicky Python", "I want to help people learn coding.")
vicky.add_skill("HTML")
vicky.add_skill("JavaScript")
nicole = Instructor("Nicole McMillan", "I have been programming for 5 years
in Python and want to spread the love")
nicole.add_skill("Python")
workshop.add_participant(jane)
workshop.add_participant(lena)
workshop.add_participant(vicky)
workshop.add_participant(nicole)
workshop.print_details
# =>
# Workshop - 12/03/2014 - Shutl
#
# Students
# 1. Jane Doe - I am trying to learn programming and need some help
# 2. Lena Smith - I am really excited about learning to program!
#
# Instructors
# 1. Vicky Ruby - HTML, JavaScript
# I want to help people learn coding.
# 2. Nicole McMillan - Ruby
# I have been programming for 5 years in Ruby and want to spread the love
#
Bonus
The print_details method currently does a number of different things, like printing out
workshop details, the list of Students and the list of Coaches.
Create separate methods to print the workshop details (date and classroom), a method
to print out the students and one to print out the coaches. Call these
from print_details instead of having all the code there.
Hint: look into defining private class methods.