Kuis Latihan Python

Reading time ~3 minutes

Karena telah separuh ebook dipelajari, maka ada kuis latihan. Untuk kuisnya kita disuruh mendownload file yang ada di http://learnpythonthehardway.org/python3/exercise26.txt, tugas kita selanjutnya adalah mengkoreksi dari file yang sudah di download. File tadi berisi kode latihan yang sudah dipelajari, jadi latihanini tujuan sebenarnya unuk mengingat kembali apa yang telah dipelajari.

File tugas kali ini tidak saya rubah ke bahasa Indonesia, hanya saya beri komentar bahasa Indonesia dimana letak kesalahannya. Berikut hasil koreksi saya :

print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
# kurang input height
height = input()
# kurang tanda kurung satu
print("How much do you weigh?", end=' ')
weight = input()

print(f"So, you're {age} old, {height} tall and {weight} heavy.")

# tambah modul argv
from sys import argv

script, filename = argv

# nama variable seharusnya filename
txt = open(filename)

# kurang f, untuk membuat format string
print(f"Here's your file {filename}:")
# variabel nama kurang
print(txt.read())

print("Type the filename again:")
file_again = input("> ")

txt_again = open(file_again)

# perlu tanda (.)
print(txt_again.read())

# diganti dengan petik dua
print("Let's practice everything.")
print('You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.')

poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""

# kurang tanda petik dua
print("--------------")
print(poem)
# kurang petik dua
print("--------------")

# kurang angka 6
five = 10 - 2 + 3 - 6
# kurang penutup kurung
print(f"This should be five: {five}")

# kurang tanda : di fungsi
def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    # kurang operasi matematika
    crates = jars / 100
    return jelly_beans, jars, crates

start_point = 10000
# kurang crates
beans, jars, crates = secret_formula(start_point)

# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")

start_point = start_point / 10

print("We can also do that this way:")
# kurang tanda (_) pada start point
formula = secret_formula(start_point)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))



people = 20
# menghapus huruf e agar sama semua
cats = 30
dogs = 15


if people < cats:
    # kurang tanda kurung
    print("Too many cats! The world is doomed!")

if people < cats:
    print("Not many cats! The world is saved!")

if people < dogs:
    print("The world is drooled on!")

# kurang tanda :
if people > dogs:
    print("The world is dry!")


dogs += 5

if people >= dogs:
    print("People are greater than or equal to dogs.")

# kurang tanda :
if people <= dogs:
# kurang tanda petik dua
    print("People are less than or equal to dogs.")

# kurng tanda =
if people == dogs:
    print("People are dogs.")
comments powered by Disqus