String, Int, and List Review
This exercise helps assess your mastery of Python variables using string, integer, and list data types.
Video Walkthrough
Use this video to follow along with the steps in this lab.
Instructions
Perform the following Python programming tasks.
- Create a new file called
review1.py. - Create the code in
review1.pythat implements the following requirements. - Print the multiplication of 7 and 4.
- Print the result of dividing 8 by 4.
- Print the result of dividing 7/3 as an integer (rounded down using Python's default).
- For example, if the result of dividing 7/3 is 2.6667, your program should print
2.
- For example, if the result of dividing 7/3 is 2.6667, your program should print
- Print raising 5 to the power of 4.
- Create a string variable named
first_namewith the value of your first name (properly capitalized). - Create a string variable named
last_namewith the value of your last name (properly capitalized). - Print your first name and last name with a space between them using the
first_nameandlast_namevariables. (Do not modify thefirst_nameorlast_namevariables to add a space.) - Print the
first_namevariable in lowercase. - Print the
last_namevariable in upper case. - Create a variable named
lower_namethat contains your full name, but lowercase. Use thefirst_nameandlast_namevariables to obtain your name.- For example, if
first_nameis "Jim" andlast_nameis "Marquardson", you should print "Jim Marquardson" using the variables and adding a space in between. Concatenate the three elements together.
- For example, if
- Print
lower_name. - Print the number of characters in
lower_name. - Create a
yearvariable with an integer of the current year. - Create a
next_yearvariable by adding one to theyearvariable. - Print the value of
year. - Print the value of
next_year. - Create a list variable named
countriescontaining the names of 3 countries. - Print the value of the second country in the list.
- Add a fourth country to the
countrieslist. - Print the
countrieslist. - Remove a country from the
countrieslist. - Print the
countrieslist. - Print the length of the countries list.
- Save the file.
- Run the file. Fix any syntax errors or logic errors.
Challenge
- Edit review1.py to add the following requirements.
- Create a nested list named
nessywith three sublists. Populate the sublists with any data you want. - Print the value of each item in all sublists using the list indexes.
- Save and run the file.
Reflection
- Which elements of the assignment were most challenging?
- How does this coding exercise compare to previous coding experiences you might have had?