Lompat ke konten Lompat ke sidebar Lompat ke footer

Exercises - Jupyter Notebook

Number (Angka)
Python mendukung tipe data angka, termasuk integer (int) dan floating-point (float).
Variable Assignment (Penugasan Variabel)
Variabel digunakan untuk menyimpan data.

String (Teks)
String adalah tipe data yang digunakan untuk teks.

Printing (Cetak)
Menggunakan fungsi print() untuk mencetak data ke layar.

List (Daftar)
List adalah tipe data yang digunakan untuk menyimpan koleksi elemen.

Dictionaries (Kamus)
Dictionary adalah tipe data yang digunakan untuk menyimpan pasangan kunci-nilai.

Booleans (Boolean)
Tipe data boolean hanya memiliki dua nilai, True atau False.

Tuples (Tuple)
Tuple adalah tipe data yang mirip dengan list, tetapi bersifat tidak dapat diubah.

Sets (Himpunan)
Set adalah tipe data yang digunakan untuk menyimpan elemen unik tanpa urutan tertentu.

Comparison Operators (Operator Perbandingan)
Operator perbandingan digunakan untuk membandingkan nilai.

Logical Operators (Operator Logika)
Operator logika digunakan untuk menggabungkan kondisi.

If, Elif, Else (Percabangan)
Percabangan digunakan untuk mengambil keputusan berdasarkan kondisi.

For Loops (Perulangan For)
Perulangan for digunakan untuk mengulangi sejumlah elemen.

While Loops (Perulangan While)
Perulangan while digunakan untuk mengulangi kode selama kondisi tertentu terpenuhi.

Range() (Rentang)
Fungsi range() digunakan untuk menghasilkan rentang bilangan.

List Comprehension
List comprehension adalah cara singkat untuk membuat list.

Functions (Fungsi)
Fungsi digunakan untuk mengelompokkan kode yang dapat dipanggil ulang.

Lambda Expressions
Lambda expressions digunakan untuk membuat fungsi anonim.

Map dan filter
Fungsi map() dan filter() digunakan untuk memproses list.

Methods (Metode)
Metode adalah fungsi yang terkait dengan objek.


Exercises (UTS)

1. What is 7 to the power of 4?

 

2.  Split this string:

s = "Hi there Sam!"

into a list. 

 

3.  ['Hi', 'there', 'dad!']

 Given the variables:

planet = "Earth"
diameter = 12742

 Use .format() to print the following string:

The diameter of Earth is 12742 kilometers.
 
 
4. Given this nested list, use indexing to grab the word "hello" 
 
 
5. Given this nested dictionary grab the word "hello". Be prepared, this will be annoying/tricky
 
 
6.  What is the main difference between a tuple and a list? 

7. Create a function that grabs the email website domain from a string in the form: **
user@domain.com

So for example, passing "user@domain.com" would return: domain.com
 
8. Create a basic function that returns True if the word 'dog' is contained
 in the input string. Don't worry about edge cases like a punctuation 
being attached to the word dog, but do account for capitalization.

9. Create a function that counts the number of times the word "dog" occurs in a string. Again ignore edge cases. 
 
10. Use lambda expressions and the filter() function to filter out words 
from a list that don't start with the letter 's'. For example:**
seq = ['soup','dog','salad','cat','great']
Use lambda expressions and the filter() function to filter out words from a list that don't start with the letter 's'. For example:**
seq = ['soup','dog','salad','cat','great']

should be filtered down to:

['soup','salad']

11. Final Problem
You are driving a little too fast, and a police officer stops you. Write a function to return one of 3 possible results: "No ticket", "Small ticket", or "Big Ticket". If your speed is 60 or less, the result is "No Ticket". If speed is between 61 and 80 inclusive, the result is "Small Ticket". If speed is 81 or more, the result is "Big Ticket". Unless it is your birthday (encoded as a boolean value in the parameters of the function) -- on your birthday, your speed can be 5 higher in all cases. 
 
 
 
 
 
 
 

Posting Komentar untuk "Exercises - Jupyter Notebook"