Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:46:40+00:00 2026-06-06T07:46:40+00:00

I have this; import operator cuts = { Emerald : (10,125), Oval : (20,150),

  • 0

I have this;

import operator
cuts = { "Emerald" : (10,125),
         "Oval" : (20,150),
         "Pear" : (35, 175),
         "Plumbbob" : (50,200),
         "Marquis" : (75, 230),
         "Crystal Ball" : (100, 260),
         "Brilliant" : (250, 350),
         "Star Cut" : (400,400),
         "Heart-shaped" : (1000, 500)
         }

def best(amount):
    "Returns most profitable cut's name."
    max_name = ""
    max_value = -10000
    for k,v in cuts.iteritems():
        value = ((float(amount) * (v[1] - 100) / 100)) - v[0]
        if value > max_value:
            max_value = value
            max_name = k
    return max_name

def create_table():
    """Creates a table like

       0-40 emerald
       40-45 Oval
       ...
       2000 + Heart-shaped
    """

But I am stuck at writing create_table. This code is for helping with a game I am playing. best funciton, given an amount, returns most profitable cut name for that amount. I want to create a table that shows me ranges. For example, for amounts between 0-40, best cut is emerald, between 40-45 best cut is Oval etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:46:42+00:00Added an answer on June 6, 2026 at 7:46 am
    def create_table():
        curname = None
        for amount in xrange(2500):
            name = best(amount)
            if name != curname:
                if curname is not None:
                    print "%d-%d %s" % (minamt, amount-1, curname)
                curname = name
                minamt = amount
        print "%d-%d %s" % (minamt, amount-1, curname)
    

    (not tested, btw)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: import re def doReplace(toReplace): i = 1 def chapterReplacer(_): result
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
I have this appdelegate.h #import <UIKit/UIKit.h> @interface appDelegate : NSObject <UIApplicationDelegate> { UIWindow *window;
So I have this need to import (currently) about 15k products. Each product has
I have a program like this - import weka.core.stemmers.SnowballStemmer; public class TestProject{ public static
I have this regex that uses forward and backward look-aheads: import re re.compile(<!inc\((?=.*?\)!>)|(?<=<!inc\(.*?)\)!>) I'm
I have this code in my forms.py : from django import forms from formfieldset.forms
I have this code to create a webapp in my server: import web urls
I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
The operator.itemgetter() function works like this: >>> import operator >>> getseconditem = operator.itemgetter(1) >>>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.