I need help in converting this program into a singleton design pattern. I have read this article on stack overflow - Link.
I have been trying to figure out how to do this for some days now.
I understood that singleton design pattern is a way to provide one and only one object of a particular type. It involves only one class to create methods and specify the objects. Also i have written some programs but still i am clueless how to go about doing this.
Actually i am learning object oriented concepts.
import requests
URL = "http://labs.bible.org/api/?passage="
print("To terminate program type 'exit'")
while True:
cmd = input("Type 'verse' for a random Bible verse: ")
if cmd.lower()=="verse":
#to fetch the result from the API
#requests.get needs a url
response = requests.get(URL+"random")
proper_text =":".join(response.text[3:].split(''))
print(proper_text)
elif cmd.lower()=="exit":
print("Program terminated")
break
else:
print("Waiting for valid command")
Aucun commentaire:
Enregistrer un commentaire