Conditional Statements

  •  If Cancitional
 "pernyataan if," yang merupakan struktur kontrol yang digunakan untuk membuat keputusan dalam kode. Pernyataan "if" untuk menjalankan blok kode jika kondisi tertentu terpenuhi.

Complete the code in the editor to find the average rating for free apps.

Inside the for loop:
Assign the price of an app as a float to a variable named price. The price is the fifth element in each row (don't forget that the index starts at 0).
If price == 0.0, append the value stored in rating to the free_apps_ratings list using the list_name.append() command (note the free_apps_ratings is already defined in the code editor). Be careful with indentation.
Outside the for loop body, compute the average rating of free apps. Assign the result to a variable named avg_rating_free. The ratings are stored in the free_apps_ratings list.






  • Booleans
Booleans (dalam pemrograman, sering disebut bool) adalah tipe data yang mewakili nilai kebenaran atau keputusan dalam pemrograman. Tipe data boolean hanya memiliki dua nilai yang valid: True (benar) atau False (salah). Booleans digunakan untuk melakukan evaluasi kondisi dan pengambilan keputusan dalam kode.


In the code editor, we've already initialized the variable a_price with a value of 0. Transcribe the following sentences into code by making use of if statements:
If a_price is equal to 0, then print the string 'This is free' (remember to use the == operator for equality).
If a_price is equal to 1, then print the string 'This is not free'.



  • The Average Rating of Non-free Apps
The Average Rating of Non-free Apps" adalah sebuah konsep yang umumnya digunakan dalam analisis aplikasi seluler atau perangkat lunak untuk mengevaluasi rata-rata peringkat (rating) dari aplikasi berbayar atau aplikasi yang tidak gratis. Kegunaan dari konsep ini termasuk:
Penilaian Kualitas Aplikasi: Menghitung rata-rata peringkat dari aplikasi berbayar membantu pengguna atau pengembang untuk mendapatkan gambaran tentang kualitas aplikasi tersebut. Rata-rata peringkat yang tinggi pada aplikasi berbayar dapat menunjukkan bahwa pengguna puas dengan fitur dan kinerja aplikasi tersebut.
Pembandingan dengan Aplikasi Gratis: Menghitung rata-rata peringkat aplikasi berbayar juga memungkinkan pembandingan dengan aplikasi gratis. Ini dapat membantu pengguna atau pengembang dalam mengambil keputusan apakah sebaiknya mereka memilih aplikasi berbayar atau aplikasi gratis berdasarkan kualitas dan nilai yang mereka tawarkan.
Pemantauan Kepuasan Pengguna: Pengukuran rata-rata peringkat dari aplikasi berbayar seiring waktu dapat memberikan wawasan tentang bagaimana tingkat kepuasan pengguna berkembang. Jika rata-rata peringkat menurun, ini mungkin menjadi tanda bahwa aplikasi memerlukan perbaikan atau pembaruan.
Keputusan Bisnis: Pengembang dan perusahaan yang menjual aplikasi berbayar dapat menggunakan rata-rata peringkat sebagai alat untuk mengukur keberhasilan bisnis mereka. Rata-rata peringkat yang baik dapat mendorong penjualan dan pembaruan aplikasi.


Modify the existing code in the editor on the right to compute the average rating of non-free apps.
Change the name of the empty list from free_apps_ratings to non_free_apps_ratings (the list we defined before the for loop).
Change the condition if price == 0.0 to account for the fact that we now want to isolate only the ratings of non-free apps.
Change free_apps_ratings.append(rating) to make sure the ratings are appended to the new list non_free_apps_ratings.
Compute the average value by summing up the values in non_free_apps_ratings and dividing by the length of this list. Assign the result to avg_rating_non_free.
Optional exercise: Inspect the value of avg_rating_non_free and compare the average with that of free apps (the average rating of free apps is approximately 3.38 — we computed it in the first screen). Can we use the average values to say that free apps are better than non-free apps, or vice versa?


  • The Average Rating of Gaming Apps
Following the same techniques we used in the diagram above, compute the average rating of non-gaming apps.

Initialize an empty list named non_games_ratings.
Loop through the apps_data list of lists (make sure you don't include the header row). For each iteration of the loop:
Assign the rating of the app as a float to a variable named rating (the index number of the rating column is 7).
Assign the genre of the app to a variable named genre (index number 11).
If the genre is not equal to 'Games', append the rating to the non_games_ratings list.
Compute the average rating of non-gaming apps, and assign the result to a variable named avg_rating_non_games.
Optional exercise: Compare the average rating of gaming apps (3.69) with that of non-gaming apps. Why do you think we see this difference?




  • Multiple Conditions
Complete the code in the editor to compute the average rating of free gaming apps.
Inside the for loop, append the rating to the free_games_ratings list if the price is equal to 0.0 and the genre is equal to 'Games'.
Outside the for loop, compute the average rating of free gaming apps. Assign the result to a variable named avg_rating_free_games.



  • The Or Operator
Complete the code in the editor to compute the average rating of the apps whose genre is either "Social Networking" or "Games."
Inside the for loop, append the rating to the games_social_ratings list if the genre is either 'Social Networking' or 'Games'.
Outside the for loop, compute the average rating of the apps whose genre is either "Social Networking" or "Games," and assign the result to a variable named avg_games_social.


  • Combining Logical Operator
Compute the average rating of non-free apps whose genre is either "Social Networking" or "Games."
Assign the result to a variable named avg_non_free.
We'll try to solve this exercise without any guidance. You may feel a bit stumped at first, but we've practiced the steps needed to solve this kind of exercise several times. Essentially, the code is almost identical to what we used to extract the ratings for free gaming or social networking apps.



  • Comparation Operators
Compute the average rating of the apps that have a price greater than 9.

Using a for loop, isolate the ratings of all the apps that have a price greater than 9. When you iterate over apps_data, make sure you don't include the header row.
Find the average value of these ratings and assign the result to a variable named avg_rating.
Find out how many apps have a price greater than 9 and assign the result to a variable named n_apps_more_9. You can use the list of ratings from the previous question to find the answer.
Find out how many apps have a price less than or equal to 9 and assign the result to a variable named n_apps_less_9. The list of ratings from the first question can help you find a quick answer.



  • The Else Clause
Complete the code in the editor to label each app as "free" or "non-free" depending on its price.

Inside the for loop:
If the price of the app is 0.0, then label the app as "free" by appending the string 'free' to the current iteration variable.
Else, label the app "non-free" by appending the string 'non-free' to the current iteration variable. Make sure you don't write 'non_free' instead of 'non-free'.
By adding labels to the end of each row, we basically created a new column. Name this column "free_or_not" by appending the string 'free_or_not' to the first row of the apps_data data set. Make sure this is done outside the for loop.
Print the header row and the first five rows to see some of the changes we made.



  • The Elif Clause
Complete the code in the editor to label each app as "free," "affordable," "expensive," or "very expensive." Inside the loop:If the price of the app is 0, label the app as "free" by appending the string 'free' to the current iteration variable.
If the price of the app is greater than 0 and less than 20, label the app as "affordable". For efficiency purposes, use an elif clause.If the price of the app is greater or equal to 20 and less than 50, label the app as "expensive". For efficiency purposes, use an elif clause.
If the price of the app is greater or equal to 50, label the app as "very expensive". For efficiency purposes, useanelifclause.
Name the newly created column "price_label" by appending the string 'price_label' to the first row of the apps_data data set.
Inspect the header row and the first five rows to see some of the changes you made.








Komentar

Postingan populer dari blog ini

Cara Chek lokasi berdasarkan foto &video

cara menghitung diskon php_struktur kontrol

Praktek install mutillidae di Kali Linux