Warm tip: This article is reproduced from serverfault.com, please click

Not able to display random words in python

发布于 2020-11-29 05:34:41
import random
from words import voc_list
import time
from plyer import notification

def get_word():
    word = random.choice(voc_list)
    return word.upper()

if __name__ == "__main__":
    while True:
    
        notification.notify(
        title = "Here is another vocablary word :-"
        The_word = random.choice(voc_list)
        Timeout = 8
        )
    
    
    
    

I am trying to make a vocabulary reminder that tells you a new word in every 2 hours. I made a list of words along with their meaning and trying to display any one randomly for which I have used from words import voc_list but why it is showing as invalid syntax here The_word = random.choice(voc_list)

Questioner
Hardyk Mahendru
Viewed
0
Abhinav Sharma 2020-11-29 13:52:54

I think you are passing multiple parameters in the notify method and missing commas for the parameters.

import random
from words import voc_list
import time
from plyer import notification

def get_word():
    word = random.choice(voc_list)
    return word.upper()

if __name__ == "__main__":
    while True:
    
        notification.notify(
        title = "Here is another vocablary word :-",
        The_word = random.choice(voc_list),
        Timeout = 8
        )

If you are using your imported modules correctly, then this should work.