简体   繁体   中英

What is the correct way of generating a base-10 naming scheme (i.e. generating polygon names)?

I'm trying to make a list or dictionary of polygon names , so that I can generate a name for any given number of sides, eg if the input is 18, then the output would be "octadecagon" I feel like there should be a simple way to do this but I'm not sure how

I thought that maybe I could brute force it by using integer division and a remainder, but that seemed too tedious and ineffective

Just use a dictionary:

names = {3: 'triangle', 4: 'rectangle', 18: 'octadecagon'}

You can define a name() function that uses it:

def name(num):
    return names[num]

or just use names[number] to get the name of the shape you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM