Python Forum

Full Version: 0 error but Not printed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm having this trouble. The code has no mistake but when I try, no result


#deklarasi kelas kata
KATA_GANTI_1    = ['aku', 'mereka', 'kami',  'kita', 'saya', 'beta', 'daku', 'engkau']
KATA_GANTI_2    = ['kamu' , 'anda', 'engkau', 'kau', 'dikau', 'mu' , 'kalian' , 'kamu sekalian' , 'sekalian' ]
KATA_GANTI_3    = ['mereka','nya','ia','beliau','dia','bapak', 'ayah', 'ibu', 'mama' 'kakak', 'kakek', 'adik', 'nenek', 'abang', 'tante', 'bibi', 'paman']
SUBJEK          = [KATA_GANTI_1 , KATA_GANTI_2, KATA_GANTI_3]
PREDIKAT        = ['mengatakan' , 'berkata' , 'bertanya' , 'menanyakan' , 'memerintah' , 'memerintahkan' , 'menyuruh' , 'memberitahu']
KATA_HUBUNG_BERITA          = ['bahwa' , 'supaya']
KATA_HUBUNG_TANYA_TOTAL     = ['apakah' , 'kah']
KATA_HUBUNG_TANYA_PARSIAL   = ['tentang',]
KET_SIFAT   = ['sangat', 'lebih', 'kurang', 'cukup' ,'paling' , 'agak']
KATA_SIFAT  = ['cantik' 'jelek' , 'tinggi' , 'pendek' , 'kesal' , 'rapi' , 'banyak' , 'berat' , 'hebat' ]
KET_WAKTU   = ['kemarin', 'besok', 'sekarang', 'kini', 'lusa', 'siang', 'malam', 'pagi', 'sebelum', 'sesudah', 'baru saja' , 'barusan','saat', 'sesaat', 'sewaktu', 'seketika', 'yang lalu' , 'tadi']
#==========================================================================================================#
#token
from nltk.tokenize import word_tokenize

nama = raw_input ("Masukkan Kalimat : ")
tokens = word_tokenize(nama)
kalsung = (nama[nama.find('“') + 1:nama.find('”')])
ksk     = (nama[nama.find('.') + 1:nama.find('“')])
if  ksk in KATA_GANTI_1 :
    print (ksk +" bahwa " + kalsung)
the output should be "Bulan yang lalu saya mengatakan bahwa saya mengerjakan sendiri". can anyone help me? Thanks!


[Image: unknown.png?width=1440&height=529]
first of all, the condition in the if statement in the code from the image is not the same as the one in code from the post
if str(ksk) in KATA_GANTI_1 == KATA_GANT1:
second, although syntacticly correct it doesn't make sense, because it compares a bool with a list and will never be True
(Jul-14-2018, 05:04 AM)buran Wrote: [ -> ]first of all, the condition in the if statement in the code from the image is not the same as the one in code from the post
if str(ksk) in KATA_GANTI_1 == KATA_GANT1:
second, although syntacticly correct it doesn't make sense, because it compares a bool with a list and will never be True


it's the same result. with or without str still cant print
int's not the str(). Actually it is useless - raw_input will always return str anyway
on the image
if str(ksk) in KATA_GANTI_1 == KATA_GANT1:
left-hand side str(ksk) in KATA_GANTI_1 will be True or False

rigth-hand side is always ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

so your if statement will be
if True == ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

or

if False == ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

Neither case will ever be True
(Jul-14-2018, 08:17 AM)buran Wrote: [ -> ]int's not the str(). Actually it is useless - raw_input will always return str anyway
on the image
if str(ksk) in KATA_GANTI_1 == KATA_GANT1:
left-hand side str(ksk) in KATA_GANTI_1 will be True or False

rigth-hand side is always ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

so your if statement will be
if True == ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

or

if False == ['aku', 'mereka', 'kami', 'kita', 'saya', 'beta', 'daku', 'engkau']

Neither case will ever be True

I tried to use ur suggest but it not work either. the statement is, if one of KATA_GANTI_1 word list inside ksk then print
(Jul-14-2018, 11:04 AM)Piqurs Wrote: [ -> ]I tried to use ur suggest but it not work either.
I didn't make any suggestion, just explained why your code does not work