20 == '20'
Classwork 4
Python Basics
Question 1
Using Python operations only, calculate below: \[\frac{2^5}{7 \cdot (4 - 2^3)}\]
Answer
Question 2
For each expression below, what is the value of the expression? Explain thoroughly.
= 4.0
x = .5
y
< y or 3*y < x x
Answer
Question 3
= "$10.00"
fare = "2.00$"
tip = "$ 0.80" tax
Write a Python code that uses slicing and the print()
function to print out the following message:
Answer
Question 4
= [100, 144, 169, 1000, 8] list_variable
Write a Python code that uses print()
and max()
functions to print out the largest value in the list, list_variable
, as follows:
Answer
Question 5
= [3, 2, 1, 0] vals
- Use a
while
loop to print each value of the list [3, 2, 1, 0], one at a time. - Use a
for
loop to print each value of the list [3, 2, 1, 0], one at a time.
Answer
Question 6
Assign the value 7 to the variable
guess_me
, and the value 1 to the variablenumber
.Write a
while
loop that comparesnumber
withguess_me.
- Print ‘too low’ if
number
is less than guess me. - If
number
equalsguess_me
, print ‘found it!’ and then exit the loop. - If
number
is greater thanguess_me
, print ‘oops’ and then exit the loop. - Increment
number
at the end of the loop.
- Print ‘too low’ if
Write a
for
loop that comparesnumber
withguess_me.
- Print ‘too low’ if
number
is less than guess me. - If
number
equalsguess_me
, print ‘found it!’ and then exit the loop. - If
number
is greater thanguess_me
, print ‘oops’ and then exit the loop. - Increment
number
at the end of the loop.
- Print ‘too low’ if
Answer
Question 7
- You are given a variable value that contains a string.
= "$320" value
- Write a Python program to:
- Attempt to convert value to a floating-point number using
float()
. - If the conversion is successful, print: “You entered:
”. - If the conversion fails (e.g., the value is not a valid number), print: “That’s not a valid number!”.
- Attempt to convert value to a floating-point number using
- Use a
try
-except
block to handle the potential error.
Answer
Question 8
- Import the
pandas
library aspd
. - Install the
itables
library. - From
itables
, import the functionsinit_notebook_mode
andshow
.
Answer
Discussion
Welcome to our Classwork 4 Discussion Board! 👋
This space is designed for you to engage with your classmates about the material covered in Classwork 4.
Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.
If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 4 materials or need clarification on any points, don’t hesitate to ask here.
All comments will be stored here.
Let’s collaborate and learn from each other!