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.
x = 4.0
y = .5
x < y or 3*y < xAnswer
Question 3
fare = "$10.00"
tip = "2.00$"
tax = "$ 0.80"Write a Python code that uses slicing and the print() function to print out the following message:
Answer
Question 4
list_variable = [100, 144, 169, 1000, 8]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
vals = [3, 2, 1, 0]- Use a
whileloop to print each value of the list [3, 2, 1, 0], one at a time. - Use a
forloop 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
whileloop that comparesnumberwithguess_me.- Print ‘too low’ if
numberis less than guess me. - If
numberequalsguess_me, print ‘found it!’ and then exit the loop. - If
numberis greater thanguess_me, print ‘oops’ and then exit the loop. - Increment
numberat the end of the loop.
- Print ‘too low’ if
Write a
forloop that comparesnumberwithguess_me.- Print ‘too low’ if
numberis less than guess me. - If
numberequalsguess_me, print ‘found it!’ and then exit the loop. - If
numberis greater thanguess_me, print ‘oops’ and then exit the loop. - Increment
numberat the end of the loop.
- Print ‘too low’ if
Answer
Question 7
- You are given a variable value that contains a string.
value = "$320"- 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-exceptblock to handle the potential error.
Answer
Question 8
- Import the
pandaslibrary aspd. - Install the
itableslibrary. - From
itables, import the functionsinit_notebook_modeandshow.
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!