Python Forum
Is there a better way to write this case scenario?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a better way to write this case scenario?
#11
the input is height and width. if height>width the orientation is portrait, and if width>height - orientation is Landscape. No matter if user calls page_info(height=297, width=210) or page_info(height=210, width = 297) it is A4 size. So, I take height and width and create tuple with first element the bigger of the height/width and second element - the other one. that is p-dimensions that I use as key. Of course I don't order page_size - I don't need to sorted dict. As you know dict is unordered by design up untill 3.6.
I know my dict is not exhaustive for all possible page sizes - it's up the OP to implement full nomenclature if s/he wants to do so. but for page sizes A0-A4 it's OK and if at least one of the dimensions is not standard one it will return unknown size. I have provided an example for 4 possible combinations and all work fine.
Reply


Messages In This Thread
RE: Is there a better way to write this case scenario? - by buran - Sep-25-2017, 07:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switch case or match case? Frankduc 9 4,915 Jan-20-2022, 01:56 PM
Last Post: Frankduc
  Help: write 'case' with Python ICanIBB 2 1,966 Jan-27-2021, 09:39 PM
Last Post: Larz60+
  How to write switch case statement in Python pyhelp 9 9,699 Nov-11-2018, 08:53 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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