+ 1

Error please help :<

The President's phone is broken He is not very happy. The only letters still working are uppercase E, F, I, R, U, Y. An angry tweet is sent to the department responsible for presidential phone maintenance. Kata Task Decipher the tweet by looking for words with known meanings. FIRE = "You are fired!" FURY = "I am furious." If no known words are found, or unexpected letters are encountered, then it must be a "Fake tweet." Notes The tweet reads left-to-right. Any letters not spelling words FIRE or FURY are just ignored If multiple of the same words are found in a row then plural rules apply - FIRE x 1 = "You are fired!" FIRE x 2 = "You and you are fired!" FIRE x 3 = "You and you and you are fired!" etc... FURY x 1 = "I am furious." FURY x 2 = "I am really furious." FURY x 3 = "I am really really furious." etc... Examples ex1. FURYYYFIREYYFIRE = "I am furious. You and you are fired!" ex2. FIREYYFURYYFURYYFURRYFIRE = "You are fired! I am really furious. You are fired!" ex3. FYRYFIRUFIRUFURE = "Fake tweet." here is my code. def fire_and_fury(tweet): fur_sent = 'I am furious. ' fir_sent = 'You are fired!' fur_c = tweet.count('FURY') fir_c = tweet.count('FIRE') if fur_c == 1 and fir_c == 1: return fur_sent + fir_sent if fur_c > 1: fur_sent[4] += ' really '*fur_c if fir_c > 1: fir_sent[3] += ' and you '*fir_c print(fur_sent, fir_sent) The code returns an error and I need help with how to fix it, please

21st Oct 2021, 12:42 AM
Ailana
Ailana - avatar
1 Answer
+ 1
Your error has to do with attempting to append using "+=" with a string while using an index. This won't solve the task entirely, but maybe you'll be able to complete the remaining portion afterward. Instead try setting the string value back to the variable name you're using like; fur_sent = fur_sent[:4] + (' really ' * fur_c) or with an f-string fur_sent = f"{fur_sent[:4]}{' really ' * fur_c}" the same goes for fir_sent
21st Oct 2021, 1:08 AM
ChaoticDawg
ChaoticDawg - avatar