Advertisement
SimeonTs

SUPyF Objects and Classes - 07. Websites

Aug 12th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. """
  2. Objects and Classes
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/950#6
  4.  
  5. SUPyF Objects and Classes - 07. Websites
  6.  
  7. Problem:
  8. You have been tasked to create an ordered database of websites. For the task you will need to create a class Website,
  9. which will have a Host, a Domain and Queries.
  10. The Host and the Domain are simple strings.
  11. The Queries, is Collections of strings.
  12. You will be given several input lines in the following format:
  13. {host} | {domain} | {query1,query2. . .}
  14. Note: There will always be a host and a domain, but there might NOT be ANY queries.
  15. The input sequence ends, when you receive the command “end”. Then you must print all websites in the following format:
  16. https://www.{host}.{domain}/query?=[{query1]&[{query2}]&[query3]. . .
  17. In case there are NO queries, just print:
  18. https://www.{host}.{domain}
  19.  
  20. Examples:
  21.  
  22. INPUT:
  23.    softuni | bg | user,course,homework
  24.    judge.softuni | bg | contest,bg
  25.    google | bg | search,query
  26.    zamunda | net
  27.    end
  28. OUTPUT:
  29.    https://www.softuni.bg/query?=[user]&[course]&[homework]
  30.    https://www.judge.softuni.bg/query?=[contest]&[bg]
  31.    https://www.google.bg/query?=[search]&[query]
  32.    https://www.zamunda.net
  33. """
  34.  
  35.  
  36. class Website:
  37.     def __init__(self, host, domain, queries):
  38.         self.host = host
  39.         self.domain = domain
  40.         self.queries = queries
  41.  
  42.  
  43. web_addresses = []
  44.  
  45. while True:
  46.     inp = input()
  47.     if inp == "end":
  48.         break
  49.     data = [item for item in inp.split(" | ")]
  50.     if len(data) > 2:
  51.         queries_ = [item for item in data[2].split(",")]
  52.         web_address = Website(host=data[0], domain=data[1], queries=queries_)
  53.         web_addresses += [web_address]
  54.     else:
  55.         queries_ = "Nope"
  56.         web_address = Website(host=data[0], domain=data[1], queries=queries_)
  57.         web_addresses += [web_address]
  58.  
  59. for item in web_addresses:
  60.     if item.queries != "Nope":
  61.         print(f"https://www.{item.host}.{item.domain}/query?=", end="")
  62.         counter = 1
  63.         for query in item.queries:
  64.             if counter < len(item.queries):
  65.                 print(f"[{query}]&", end="")
  66.                 counter += 1
  67.             else:
  68.                 print(f"[{query}]")
  69.     else:
  70.         print(f"https://www.{item.host}.{item.domain}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement