Homework 1
Survey, Personal Website, and Python Basics
Direction
Please submit your Jupyter Notebook for Part 3 in Homework 1 to Brightspace with the name below:
danl-210-hw1-LASTNAME-FIRSTNAME.ipynb
( e.g.,danl-210-hw1-choe-byeonghak.ipynb)
The due is February 17, 2025, 10:30 A.M.
Please send Prof. Choe an email (bchoe@geneseo.edu) if you have any questions.
Descriptive Statistics
The following provides the descriptive statistics for each part of Homework 1:
Part 1. Survey
Please complete the following survey:
Part 2. Quarto Website
- Decorate your website:
- Replace
YOUR NAMEwith your name in_quarto.ymlandindex.qmd. - Describe yourself in
index.qmd. - Add the picture file (e.g.,
png) of your profile photo toimgdirectory. Then correctimg/profile.pnginindex.qmdaccordingly. - Add the PDF file of your resumé to the website working directory in your laptop.
- Correct links for your resumé, LinkedIn, email, and optionally social media.
- Make sure that you do not have any broken links in your website.
- Add a menu of “Project” to the navigation bar using
danl_proj_nba.ipynb.
danl_proj_nba.ipynbfile is available from Brightspace.
- Add a drop-down menu of “Python Data Analysis” to the navigation bar.
- Under the menu of “Python Data Analysis”, add links for the following webpage:
- Pandas Basics using
pandas_basic.ipynb - Seaborn Basics using
seaborn_basic.ipynb pandas_basic.ipynbandseaborn_basic.ipynbfiles are available from Brightspace.
- Pandas Basics using
- Add a “Python Basics” blog post to your blog using Jupyter Notebook.
- In your “Python Basics” blog post, briefly explain Python Basics we discussed in Lecture 4 and Lecture 5, and in Classwork 4
- Choose a proper image file for a thumbnail for a blog post.
- An YAML header template for a blog post can be found below, including an image option:
Click to Check the Answer!
---
title: BLOG_TITLE
author: YOUR_NAME
date: 2025-02-14
categories: [tag_1, tag_2, tag_3] # tags for a blog post (e.g., python)
image: "image.png"
toc: true
---- Use the 3-step git commands (
git add .,git commit -m "MESSAGE", andgit push) to update your online website.
Part 3. Python Basics
Question 0
Provide your GitHub username.
Question 1
Q1a
- Create a list of integers from 1 to 10.
- Append the number
11to the list and remove the number5.
Click to Check the Answer!
list_numbers = list(range(1, 11))
list_numbers.append(11)
list_numbers.remove(5)Q1b
- Consider the following dictionary of three employees and their salaries:
dict_salaries = {'Alice': 50000, 'Bob': 60000, 'Charlie': 70000}- Add a new employee
'Dana'with a salary of65000. - Update
'Alice'’s salary to55000. - Print all employee names and their salaries.
Click to Check the Answer!
dict_salaries = {'Alice': 50000, 'Bob': 60000, 'Charlie': 70000}
dict_salaries['Dana'] = 65000
dict_salaries['Alice'] = 55000
for name, salary in dict_salaries.items():
print(name, ":", salary)
# An f-string (formatted string literal) is a way to embed expressions
# inside string literals using curly braces `{}`.
for name, salary in dict_salaries.items():
print(f'{name}: {salary}')Question 2
Q2a
- Assign a variable
salaryto75000. - Use an
if-elif-elsestatement to print:'Low'ifsalaryis less than50,000'Medium'ifsalaryis between50,000and99,999'High'ifsalaryis100,000or more
Click to Check the Answer!
salary = 75000
if salary < 50000:
print('Low')
elif 50000 <= salary < 100000:
print('Medium')
else:
print('High')Q2b
Assign two variables,
roleandsalary, to'Manager'and85000, respectively.Use nested
if-elsestatements to print:'Eligible for bonus'if theroleis'Manager'and thesalaryis greater than80,000.'Eligible for raise'if theroleis'Analyst'and thesalaryis less than60,000.'No action needed'for all other cases.
Click to Check the Answer!
role = 'Manager'
salary = 85000
if role == 'Manager':
if salary > 80000:
print('Eligible for bonus')
else:
print('No action needed')
elif role == 'Analyst':
if salary < 60000:
print('Eligible for raise')
else:
print('No action needed')
else:
print('No action needed')Question 3
Q3a
- Consider the following list of salaries:
list_salaries = [45000, 60000, 75000, 120000, 30000]- Calculate the average salary.
- Use a
forloop to print whether each salary is'Above Average'or'Below Average'.
Click to Check the Answer!
list_salaries = [45000, 60000, 75000, 120000, 30000]
average_salary = sum(list_salaries) / len(list_salaries)
for salary in list_salaries:
if salary > average_salary:
print(f'{salary} is Above Average')
else:
print(f'{salary} is Below Average')Q3b
- Start with a
salaryof50000. - Use a
whileloop to increase the salary by5000each year until it exceeds80000. - Print the salary after each increment.
Click to Check the Answer!
salary = 50000
while salary <= 80000:
print(f'Salary: {salary}')
salary += 5000Q3c
- Consider the following dictionary of employee salaries:
salaries = {'Alice': 50000, 'Bob': 60000, 'Charlie': 70000, 'Dana': 45000}- Use a
forloop to print the names of employees who earn more than55000.
Click to Check the Answer!
salaries = {'Alice': 50000, 'Bob': 60000, 'Charlie': 70000, 'Dana': 45000}
for name, salary in salaries.items():
if salary > 55000:
print(f'{name} earns more than 55000')Q3d
data_list = [42, 3.14, 'Data Analytics', True, None, [1, 2, 3], {'key': 'value'}, (4, 5)]- Given the list above, print the data type of each element using the
type()function in aforloop. In the loop:- Convert the integer
42to a string. - Convert the float
3.14to a string, then back to a float. - Convert the boolean
Trueto an integer.
- Convert the integer
Click to Check the Answer!
data_list = [42, 3.14, 'Data Analytics', True, None, [1, 2, 3], {'key': 'value'}, (4, 5)]
for item in data_list:
print(f'Original: {item}, Type: {type(item)}')
if item == 42:
item = str(item)
print(f'Converted 42 to string: {item}, Type: {type(item)}')
if item == 3.14:
item = float(str(item))
print(f'Converted "3.14" to float: {item}, Type: {type(item)}')
if item is True:
item = int(item)
print(f'Converted True to integer: {item}, Type: {type(item)}')Question 4
Q4a
Consider the variables a and b:
a = 10
b = 0- Use a
try-exceptblock to print the result ofa / b.- If there is an error, print
'Cannot divide by zero!'.
- If there is an error, print
Click to Check the Answer!
a = 10
b = 0
try:
result = a / b
print(result)
except ZeroDivisionError:
print('Cannot divide by zero!')Q4b
- Consider the following dictionary of salaries with some missing (
None) values:
salaries = {'Alice': 50000, 'Bob': None, 'Charlie': 70000, 'Dana': None, 'Eve': 80000}- Use a
forloop with atry-exceptblock to calculate the total of non-missing salaries.
Click to Check the Answer!
salaries = {'Alice': 50000, 'Bob': None, 'Charlie': 70000, 'Dana': None, 'Eve': 80000}
total = 0
for name, salary in salaries.items():
try:
total += salary
except TypeError:
continueQuestion 5
- Import the
mathlibrary and calculate the square root of81using thesqrt()function provided by themathlibrary.
Click to Check the Answer!
import math
math.sqrt(81)