Jump to content

Code to auto update prices based on rarity and print results:

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Ha1luciNate

Ha1luciNate

    Newbie

  • Members
  • Pip
  • 9 posts
#Minecraft ore percent calculator

import random



diamond = 0.06

stone =  85.1

dirt = 9.6

gravel = 2.6

coal = 1

redstone = 0.75

iron = 0.58

gold = 0.06

sand = 3.0

sandstone = 0.5


y = ""

price = ""


list1 = (diamond, stone, dirt, gravel, coal, redstone, iron, gold, sand, sandstone)


price = int(input("What do you want DIAMOND? to cost?"))



print("Diamond: ", price/(diamond/0.06))

print("Stone: ", price/(stone/0.06))

print("Dirt: ", price/(dirt/0.06))

print("Gravel: ", price/(gravel/0.06))

print("Coal: ", price/(coal/0.06))

print("Redstone: ", price/(redstone/0.06))

print("Iron: ", price/(iron/0.06))

print("Gold: ", price/(gold/0.06))

print("Sand: ", price/(sand/0.06))

print("Sandstone: ", price/(sandstone/0.06))






So this is what I have so far. I couldn't figure out how to make it work for a specific item. The numbers listed at the tops are the amount of items found per 100. So I want to be able to enter the price for an item and have the code give me back the prices relative to that item.

I tried doing something like this"

choice = input("Pick an item:"
price = int(input("What do you want it to cost?"))

Then using those 2 variables I would use a similar approach to what I did above. I wasn't able to figure it out for a specific choice, thus the reason that I settled on diamond.

I also tried using lists.

Just a note: I've only been doing this for a few weeks so I am an UberNoob..

#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts
I am afraid your requirements are not very clear.

I think you have a collection of items each with a cost:

Now you want to pick the one with lowest value (rarely) and ask the user to input a new cost for it.

After wards you are printing them all. Have i gotten it right?

If that is the case, you need to run a loop through them all, while keeping two variables the lowest cost and the index of lowest cost.

Keep on comparing these values while going through the loop with the current one. If found lower, the current becomes your new lowest.

You might keep printing them all along or separately in the end. But upon termination of the loop you have the index and price of the lowest value item

#3
Ha1luciNate

Ha1luciNate

    Newbie

  • Members
  • Pip
  • 9 posts
I don't think you understand completely..


The numbers at the top of the screen are the rarities of the blocks. So if I had 100 then 0.06 of them would be diamond.

For example. If I want diamond to cost 2500 then the price for Stone is 2500/ (85.1 / 0.06)

Which gives:

2500 for Diamond
and
1.76 for Stone

Basically I want the items to be relatively priced compared to eachother. Also, the user would be able to pick the price for any item and the others would fall into place.

#4
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts
Initially ask the user to choose one of the types (diamond, stone etc), and assign that choice into a variable.

Now take the new price and update price of that type (you have choice saved earlier in variable so it will update the corresponding price)

In printing you can use that variable in statement (and all following statements)
price/(diamond/0.06) instead of 0.06 you can have a type (which can be any of diamond, stone etc. depending upon what a user selected previously.

#5
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 405 posts

Ha1luciNate said:

I tried doing something like this"

choice = input("Pick an item:"
price = int(input("What do you want it to cost?"))

Then using those 2 variables I would use a similar approach to what I did above. I wasn't able to figure it out for a specific choice, thus the reason that I settled on diamond.

I also tried using lists.

Just a note: I've only been doing this for a few weeks so I am an UberNoob..

Your approach is fine just replace the constant like 0.06 with the variable which contains chosen price of the type

#6
Ha1luciNate

Ha1luciNate

    Newbie

  • Members
  • Pip
  • 9 posts
#Minecraft ore percent calculator by Nate H aka Ha1luciNate


#Item rarities are here. These are based on 100 blocks mined. Change these
#values to modify the output.

diamond = 00.06
stone =  85.10
dirt = 09.60
gravel = 02.60
coal = 01.00
redstone = 00.75
iron = 00.58
gold = 00.06
sand = 03.00
sandstone = 01.00
smoothstone = "8 coal + 64 cobble"
glass = "8 coal + 64 sand"
nether = "cheap as ****"
brick = "expensive""
woodlog = "all types same price"
planks = " based on wood"
wool = "arbitrary pricing"


price = ""
choice =""
list1 = (diamond, stone, dirt, gravel, coal, redstone, iron, gold, sand, sandstone)


#Don't Touch any of this
input("""
Welcome to the Minecraft Price Generator
When you are ready press ENTER to continue.

Code by: Nate H aka Ha1luciNate""")
run = "yes"

while run == "yes":
  choice = input("""
  Pick one:
  diamond
  stone
  dirt
  gravel
  coal
  redstone
  iron
  gold
  sand
  sandstone
  
  What is your choice? ::Type it here::  """)
  price = int(input("What do you want it to cost? ::  "))
  resell = int(input("What percent do you want items to be resold for? (Just type the number)"))
  
  
  #Or this...
  if choice == "diamond":
    z = diamond
  if choice =="stone":
    z = stone
  if choice =="dirt":
    z = dirt
  if choice =="gravel":
    z = gravel
  if choice =="coal":
    z = coal
  if choice =="redstone":
    z = redstone
  if choice =="iron":
    z = iron
  if choice =="gold":
    z = gold
  if choice =="sand":
    z = sand
  if choice =="sandstone":
    z = sandstone
  
  space = "......"
  
  
  #If you want to add more items to the list copy the format here and add the variable above with the rarity.
  
  print("Item          Store sell price     Store buy price")
  print("Diamond:  ",space, price//(diamond/z), space*2, (price//(diamond/z))*(resell/100))
  print("Stone:    ",space, price//(stone/z), space*2, (price//(stone/z))*(resell/100))
  print("Dirt:     ",space, price// (dirt/z), space*2, (price// (dirt/z))*(resell/100))
  print("Gravel:   ",space, price// (gravel/z), space*2, (price// (gravel/z))*(resell/100))
  print("Coal:     ",space, price// (coal/z), space*2, (price// (coal/z))*(resell/100))
  print("Redstone: ",space, price// (redstone/z), space*2, (price/ (redstone/z))*(resell/100))
  print("Iron:     ",space, price// (iron/z), space*2, (price// (iron/z))*(resell/100))
  print("Gold:     ",space, price// (gold/z), space*2, (price// (gold/z))*(resell/100))
  print("Sand:     ",space, price// (sand/z), space*2, (price// (sand/z))*(resell/100))
  print("Sandstone:",space, price// (sandstone/z), space*2, (price// (sandstone/z))*(resell/100))
  
  input("Press ENTER to run again")




Got it.. :D

Edited by Alexander, 12 May 2011 - 05:15 PM.
Code formatting (# button or [code] tags)


#7
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
I would have used Python dictionaries instead of your group of unconnected variables, as well as encapsulated this functionality into a method that you could use any value for. Consider the following:

# WARNING: Untested!
def get_prices_based_on_item(rarity_dict, item_name):
    return_prices = {} # new dictionary
    if item_name in rarity_dict:
        divisor = rarity_dict[item_name]
        for name, rarity in rarity_dict:
            return_prices[name] = rarity / divisor
    return return_prices # Returns empty dictionary if item_name not in rarity_dict.
Then you could do something similar to print the values. This will allow you to generate a new dictionary for any item you have. It's been a while since I've been doing Python, to be honest... I should get back into this language again.
Wow I changed my sig!

#8
Ha1luciNate

Ha1luciNate

    Newbie

  • Members
  • Pip
  • 9 posts
hmm.. I have not used dictionaries before... I'll have to look into that. It looks like it would make it easier.

#9
pebz5

pebz5

    Newbie

  • Members
  • Pip
  • 5 posts
Hi, I agree that a dictionary was the thing that this needed. What dictionaries do is they allow for you to store a keyword and a corresponding value for the keyword, which is very useful when doing data storage like this. Here's the code I came up with for the application:

types = {"diamond": 0.06, "stone": 85.1, "dirt": 9.6, "gravel": 2.6, "coal": 1.0,

         "redstone": 0.75, "iron": 0.58, "gold": 0.06, "sand": 3.0, "sandstone": 3.0}


material = input("Which material would you like? ")

price = int(input("How much would you like it to cost? "))


def update_prices(mat, p):

    for x in types:

        newprices = p / (types[x] / types[mat])

        print(x, newprices)


update_prices(material, price)


I hope this helps. Good luck!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users