Postingan

DICTIONARIES & FRECUENCY TABLES

Gambar
  Dictionaries dan Frecuency Tables 1- Storing Data Store the data in the table above using two different lists. Assign the list ['4+', '9+', '12+', '17+'] to a variable named content_ratings. Assign the list [4433, 987, 1155, 622] to a variable named numbers. Store the data in the table above using a list of lists. Assign the list [['4+', '9+', '12+', '17+'], [4433, 987, 1155, 622]] to a variable named content_rating_numbers. 2- Dictionaries Map content ratings to their corresponding numbers by recreating the dictionary above: {'4+': 4433, '9+': 987, '12+': 1155, '17+': 622}. Assign the dictionary to a variable named content_ratings. Print content_ratings and examine the output carefully. Has the order we used to create the dictionary been preserved? In other words, is the output identical to {'4+': 4433, '9+': 987, '12+': 1155, '17+': 622}? We'll discuss...

FUNCTION FUNDAMENTAL

Gambar
   Function Fundamental 1- Functions Compute the sum of a_list (already defined in the code editor) without using sum(). Initialize a variable named sum_manual with a value of 0. Loop through a_list, and for each iteration add the current number to sum_manual. Print sum_manual and sum(a_list) to check whether the values are the same. 2- Built-in Function Generate a frequency table for the ratings list, which is already initialized in the code editor. Start by creating an empty dictionary named content_ratings. Loop through the ratings list. For each iteration: If the rating is already in content_ratings, then increment the frequency of that rating by 1. Else, initialize the rating with a value of 1 inside the content_ratings dictionary. Print content_ratings. 3- Creating our own Functions Recreate the square() function above and compute the square for numbers 10 and 16. Assign the square of 10 to a variable named squared_10. Assign the square of 16 to a variable named squared_...

CONDITIONAL STATEMENTS

   Conditional Statements Certainly! Here's some material about Python conditional statements to help you understand the topic better: Conditional Statements in Python Conditional statements allow you to make decisions in your Python code. They help you execute specific code blocks based on whether a given condition is true or false. In Python, you primarily use the `if`, `elif`, and `else` statements to create conditional structures. 1. The `if` Statement The `if` statement is used to test a condition. If the condition is true, the code inside the `if` block is executed. If the condition is false, the code is skipped. ```python if condition:     # Code to execute when the condition is true ``` Example: ```python x = 10 if x > 5:     print("x is greater than 5") ``` 2. The `elif` Statement The `elif` (short for "else if") statement is used when you want to test multiple conditions. You can have multiple `elif` blocks to check for different conditions in ...