Estimation/Calculation of rewards from in-game Christmas event

Hi all,

I am new to coding and I am only around 5% of the way through the Data Analyst Career Path, which includes an introduction to Python 3. This is all the coding I know and I have attempted to utilise what I have learned over the prior 2 weeks. I was struggling with the concept of return and I am still attempting to fully wrap my head around functions.

I am autistic and have struggled to learn coding in the past and this is the first “program” I have created. It has taken me 5 hours today and I am certain there will be mistakes and better ways to tackle what I did here.

The program is based on the online MMORPG Runescape and the Christmas 2021 event. I gathered my own data on christmas paper earned per hour and used that as the basis for this program.

Any constructive feedback is greatly appreciated and necessary to my continued development. I thank anyone who takes the time out of their day to have a look at what I have here. Apologies if any of the formatting is messed up, when copying the code from the workspace it seems to have altered some of the whitespace.

I have included a codebyte also.

Thanks again.

#A program to estimate the total amount of christmas wrapping paper I would earn through gameplay during the Runescape 3 Christmas Event 2021. paper_per_hour = 354 #exact amount of christmas wrapping paper gathered in one hour of average gameplay present_cost = 200 #amount of wrapping paper required to purchase one event present days = 21 #the amount of days the event runs for daily_playtime = 3 #average hours played per day print("Welcome to SpamAtHomes' Runescape 3 Christmas event rewards estimation extravaganza! This program is designed to calculate and output the estimated rewards earned throughout the duration of the 2021 event. ") #estimated christmas wrapping paper earned per minute def paper_per_minute(hourlyrate, seconds): return paper_per_hour / 60 minutely_rate = paper_per_minute(paper_per_hour, 60) minutely_rate = float(minutely_rate) print("Your estimated minutely paper earned is " + str(minutely_rate)) #estimated christmas wrapping paper earned per day def paper_per_day(hourlyrate, playtime): return paper_per_hour * daily_playtime daily_paper = paper_per_day(paper_per_hour, daily_playtime) print("Your estimated daily paper earned from this event is " + str(daily_paper)) #estimated christmas wrapping paper earned in total def event_total_paper(amount, playtime): return daily_paper * days total_estimate = event_total_paper(daily_paper, days) print("Your estimated total earned paper throughout the duration of this event is " + str(total_estimate)) #estimated christmas present rewards earned per hour def presents_per_hour(hourly_paper, cost): return paper_per_hour / present_cost hourly_presents = presents_per_hour(paper_per_hour, present_cost) print("Your estimated hourly presents earned throughout the event is " + str(hourly_presents)) #estimated christmas present rewards earned per day def presents_per_day(daily): return hourly_presents * daily_playtime daily_presents = presents_per_day(daily_playtime) print("Your estimated daily presents earned throughout the event is " + str(daily_presents)) #estimated christmas present rewards earned per week def presents_per_week(weekly): return daily_presents * 7 weekly_presents = presents_per_week(daily_paper) print("Your estimated weekly presents earned throughout the event is " + str(weekly_presents)) #estimated christmas present rewards earned in total def event_presents_total(total_amount, days): return weekly_presents * days total_earned = event_presents_total(weekly_presents, days) print("Your estimated total amount of presents earned during the event is " + str(total_earned)) #rounded total number of presents earned rounded_total = round(total_earned) print("As you can't obtain a fraction of a present, the final estimated total of presents earned during Runescape 3's 2021 Christmas event is " + str(rounded_total)) #chance to earn green santa hat - will calculate when more data is released #remaining paper at end of event after claiming all present rewards leftover_paper = total_estimate % 200 print("As one event present costs " + str(present_cost) + " you would have " + str(leftover_paper) + " event paper remaining.")
#A program to estimate the total amount of christmas wrapping paper I would earn through gameplay during the Runescape 3 Christmas Event 2021.

paper_per_hour = 354 #exact amount of christmas wrapping paper gathered in one hour of average gameplay
present_cost = 200 #amount of wrapping paper required to purchase one event present
days = 21 #the amount of days the event runs for
daily_playtime = 3 #average hours played per day

print("Welcome to SpamAtHomes' Runescape 3 Christmas event rewards estimation extravaganza! This program is designed to calculate and output the estimated rewards earned throughout the duration of the 2021 event.  ")

#estimated christmas wrapping paper earned per minute
def paper_per_minute(hourlyrate, seconds):
  return paper_per_hour / 60

minutely_rate = paper_per_minute(paper_per_hour, 60)
minutely_rate = float(minutely_rate)
print("Your estimated minutely paper earned is " + str(minutely_rate))

#estimated christmas wrapping paper earned per day
def paper_per_day(hourlyrate, playtime):
  return paper_per_hour * daily_playtime

daily_paper = paper_per_day(paper_per_hour, daily_playtime)
print("Your estimated daily paper earned from this event is " + str(daily_paper))

#estimated christmas wrapping paper earned in total
def event_total_paper(amount, playtime):
  return daily_paper * days

total_estimate = event_total_paper(daily_paper, days)
print("Your estimated total earned paper throughout the duration of this event is " + str(total_estimate))

#estimated christmas present rewards earned per hour
def presents_per_hour(hourly_paper, cost):
  return paper_per_hour / present_cost

hourly_presents = presents_per_hour(paper_per_hour, present_cost)
print("Your estimated hourly presents earned throughout the event is " + str(hourly_presents))

#estimated christmas present rewards earned per day
def presents_per_day(daily):
  return hourly_presents * daily_playtime

daily_presents = presents_per_day(daily_playtime)
print("Your estimated daily presents earned throughout the event is " + str(daily_presents))

#estimated christmas present rewards earned per week
def presents_per_week(weekly):
  return daily_presents * 7

weekly_presents = presents_per_week(daily_paper)
print("Your estimated weekly presents earned throughout the event is " + str(weekly_presents))

#estimated christmas present rewards earned in total
def event_presents_total(total_amount, days):
  return weekly_presents * days

total_earned = event_presents_total(weekly_presents, days)
print("Your estimated total amount of presents earned during the event is " + str(total_earned))

#rounded total number of presents earned
rounded_total = round(total_earned)
print("As you can't obtain a fraction of a present, the final estimated total of presents earned during Runescape 3's 2021 Christmas event is " + str(rounded_total))

#chance to earn green santa hat - will calculate when more data is released

#remaining paper at end of event after claiming all present rewards
leftover_paper = total_estimate % 200
print("As one event present costs " + str(present_cost) + " you would have " + str(leftover_paper) + " event paper remaining.")
1 Like

Hi Andrew, nice to see a fellow Scot kicking around on these forums!

I like what you’ve got here. I’ve not played Runescape in a very long time, but I feel like I’m getting the idea of what the event is simply from your code, which is a good sign.


You’ve done a good job with your commenting, it’s clear and very easy to follow. The only thing on commenting I would say is actually a positive for another aspect, in that your variable names defined at the beginning are pretty clear, and perhaps do not need the extra comments to describe what they’re used for. However commenting is pretty much entirely personal preference, so plenty of other people would probably be very grateful to have these comments also, so barely a negative!


I also appreciate that you’ve mixed everything into pure functions, that is: functions that have an exact input with a single output. This is something I always try to aim for when possible as I find it makes very clean and modular code.

One suggestion I would make for some advanced practise in future would be to create a main function that runs the full program. This would allow your print statements and function calls to all be collected together, and thus easy to see.

Generally in programming it is considered to be good practise to keep function definitions next to each other, function calls together, and to keep the two separate. It’s not required by any stretch, but can make the script easier to navigate as you don’t need to hunt for your function call.


The good thing about a personal project like this is that it’s something you can continuously come back to and improve as you learn more. One thing I would recommend is separating your function definitions into another python script, which you can then import as a module. This would keep the function definitions and the main program call clean and distinct. This isn’t something you will necessarily have encountered yet, however when you come to modules and export/import you can come back to this project and attempt this!

All in all very impressive work considering you’ve not long started to learn coding. You’ve already got very clean and easy to read code which can be half the battle sometimes. You can be proud of this and it’d be great to see you develop this further.

1 Like

RuneScape?? I thought that game would have died years ago. I liked playing it for a time.
Nice work, by all means, continue. I just started to learn codeing also and I must say it is a challenge when one is dealing with a disibility.

This is a troubling trend I see in your code
You define a function with two parameters but use none of them.
Either A. take out those parameters and just do def paper_per_minute()
because you are using global variables inside the function OR
B. actually pass in parameters as in

def paper_per_minute(hour_of_paper):
    return hour_of_paper / 60

and call it like this paper_per_hour(578)
or paper_per_hour(a variable that represents paper_earned_in_an_hour)
Let me know if that makes sense

Hey,

Thanks for taking the time to go over the small project and type out a constructive message.

For this here I was actually commenting to remind myself what was what and to make it easier for others to understand/follow without knowing what the game is.

Thank you; I haven’t actually learned about this yet and I absolutely will come back to the project and improve upon it when I learn more. I feel like it would be interesting to see how the program evolves.

I am currently only around 5% through the Data Analyst career path, thank you for the feedback it will help me :slight_smile:

1 Like

Yep, the game is still going strong, Runescape 3 being the ‘main game’ and Oldschool Runescape being a copy of a game state from 2007. I have been playing for around 18 years, so I wanted to use what little I had learned so far in a program that pertains to one of my interests.

I agree, I have been struggling with some concepts. Sometimes it is good to take a step back, even for a few days and then to return with a fresh mindset. Getting frustrated doesn’t help you learn. It can be difficult to step away when you have a goal in mind, but I am sure you will get there too!

Hi,

Thanks. This is some good feedback, although I am struggling to fully understand it. I knew when creating the functions that I was going wrong somewhere but just couldn’t fully figure it out as I was still getting expected results.

Would it be possible to clarify what you mean? It might help me understand better.

Thank you!

EDIT: do you mean rather than declaring global variables I should be putting parameters in the function to define them for a specific function or, leave the parameters empty?

For example, this is what my code is now;

def paper_per_minute(hourlyrate, seconds):
  return paper_per_hour / 60

minutely_rate = paper_per_minute(paper_per_hour, 60)
minutely_rate = float(minutely_rate)

With the globally defined variables should it be

def paper_per_minute():
  return paper_per_hour / 60

minutely_rate = paper_per_minute()
minutely_rate = float(minutely_rate)

Also, is there a way to condense what I am doing in the code here?

minutely_rate = paper_per_minute()
minutely_rate = float(minutely_rate)

Thank you so much.

Your example of using globals is correct
if you want to condense that code you could return a float return float(paper_per_hour)
As far as using parameters, I think you are confusing the declaration of a function with the calling of a function instead here is an example

int num = 4;
#Declare a function that takes in a number as a parameter and reutrns that num plus two
def add_two(num):
    return num + 2 # num is whatever you  passed to the function NOT the variable num from the outer scope

The function add_two doesnt care that there is something else named num in the outer scope to this function num is whatever you handed it
add_two(5) would return 7 add_two(6) returns 8
You CAN call the function with that variable num as well num add_two(num) returns 4
So you could DECLARE paper_per_minute like so

def paper_per_minute(totalPaper):
    reutrn totalPaper / 60

and CALL that function like so
paper_per_minute(paper_per_hour)

1 Like

Thank you! I appreciate you taking the time to respond.

I have been learning more and I am going to improve upon my original project with what I am learning.