Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
0 error but Not printed
#1
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]
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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
Reply
#6
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  coma separator is printed on a new line for some reason tester_V 4 418 Feb-02-2024, 06:06 PM
Last Post: tester_V
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 850 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  Reverse printed words hindubiceps 7 2,917 Apr-21-2020, 05:19 PM
Last Post: deanhystad
  I get "None" at the end of my printed result. dyshkant 3 2,585 Sep-06-2019, 06:31 PM
Last Post: dyshkant
  bytes not being printed as expected Skaperen 2 2,321 Aug-27-2019, 05:33 AM
Last Post: Skaperen
  Change linenumber and filename printed in exceptions like #line in C kryptomatrix 2 2,620 Jul-12-2019, 06:01 AM
Last Post: Gribouillis
  Putting an array for each string that is printed to a loop ClaudioSimonetti 1 2,315 Feb-05-2019, 12:52 PM
Last Post: perfringo
  Why A will be printed twice in the picture Shen 3 4,030 Jul-25-2018, 01:16 PM
Last Post: stranac
  [Variable as a String]>EscaSpecial characters printed CSA75 4 4,240 Mar-28-2017, 11:59 AM
Last Post: snippsat
  Best software for creating printed reports? birdieman 5 4,358 Feb-02-2017, 02:39 AM
Last Post: birdieman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020