True and False
Homework 1
Python Basics
Direction
Please submit your Jupyter Notebook for Homework 1 to the Brightspace with the name below:
danl-m1-hw1-LASTNAME-FIRSTNAME.ipynb
( e.g.,danl-m1-hw1-choe-byeonghak.ipynb
)
The due is February 13, 2024, 7:00 P.M.
Please send Byeong-Hak an email (
bchoe@geneseo.edu
) if you have any questions.Write a Python Notebook (
*.ipynb
) to answer each question.Make at least some simple comment (
# ...
) in each question.Make one text cell to explain things in each question.
Question 1
How do you assign the value 5 to a variable named x
?
Answer
Question 2
Given lst = [1, 2, 3, 4, 5]
, what does lst[1:4]
return?
Answer
Question 3
How do you create a dictionary with keys
"apple"
,"banana"
, and"cherry"
, each with the corresponding values5
,3
, and7
?How do you access the value associated with the key
"banana"
in the dictionary created above?
Answer
Question 4
For the expressions below, what is the value of the expression? Explain thoroughly.
True or False
not (100 == '100' and 25 < 36)
Answer
Question 5
- Create a new
if-elif-else
chain that prints"well done"
if a score is over90
, “good” if between40
and90
, and"bad luck"
otherwise.
Answer
Question 6
Write a for loop that prints out "coding for data analysts"
so that each word is printed in a successive iteration.
Answer
Question 7
- How do you import the
math
module in a Python script? - After importing
math
, how do you use itssqrt
function to find the square root of16
?
Answer
Question 8
- Do Question 6 in Classwork 1