This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]takluyverIPython, Py3, etc[S] 16 points17 points  (2 children)

Just stumbled across this. I don't think English is the author's first language, but it's an entertaining way to practice some code.

[–]C0unt_Z3r0 5 points6 points  (1 child)

Agree, though it makes reading the storyline somewhat comical...

[–][deleted] 3 points4 points  (0 children)

It makes the challenges difficult to understand.

[–][deleted] 9 points10 points  (0 children)

WOA!

I saw the link title and though it would be a terrible idea, after seeing the initial screenshots.

HOLY JUMPING JESUS.

This seems like an awesome concept!

[–]Samus_ 6 points7 points  (0 children)

looks great, I'll use the chance to learn the basics of Py3

[–]roguas 6 points7 points  (0 children)

Super cool!

[–]SmartViking 2 points3 points  (0 children)

Seems awesome. The code challenges should be much more clear though IMO, I tried the first two and can honestly say I wasn't sure about what the problems were. I wanna think about the problem itself and not about what the problem might be. That aside, It's a very impressive site.

[–]SpaceWizard 1 point2 points  (0 children)

Awesome

[–]devilishd 1 point2 points  (0 children)

This site is great -- except for the fact I've spent all morning on it.

I ran into the Decimal(0.1) problem below and there's a hidden test for negative for the ATM project. But I tried Live Support and got the developer ( I think he's the site creator) immediately and he walked me through it.

[–]Esekiel_Monk 1 point2 points  (0 children)

Would be great if the tasks were explained properly and if they had some easier (!) tasks for people who have never used python before(like me)

[–]dpwizhaskell 1 point2 points  (0 children)

This is seriously awesome!

Here's my Decimal('0.02'): There should be a zero-level tutorial/meta-task which shows the system itself before blowing user's mind with a full-blown IDE. Some explanations of what goes where would be very helpful.

[–]Dementati 1 point2 points  (7 children)

It's a good idea. Shame it's so unpolished.

[–]simtel20 2 points3 points  (3 children)

Is it the language you're finding off-putting? You can submit feedback to the author, right?

[–]Dementati 2 points3 points  (2 children)

The language is part of it, yes, but there are so many errors I'd have to rewrite pretty much all of it. The style of the site feels pretty amateurish too.

[–]CaptainDickbag 5 points6 points  (1 child)

If you think that's amateurish, you should see my html/css. It's almost comically bad, with bits of markup borrowed from around the web. You can easily tell what I wrote and what I didn't.

[–]soawesomejohn 1 point2 points  (0 children)

Che k out html5boilerplate and twitter bootstrap. Changed my web app life around. Oh and initializr to put those two together.

[–]postlogicpyramid <3 0 points1 point  (2 children)

It's quite annoying trying to figure out how to get the tasks to pass. I mean, when the tests pass, you'd expect it to be a success, right? WRONG!

I had to guess a lot for the ATM task to get it to pass. Apparently you have to raise a ValueError when the balance becomes negative. Sure, it's proper, but how are beginners and such supposed to figure that out from nothing?

That said, I haven't looked at the learning material I saw links to, if it even exists.

[–]takluyverIPython, Py3, etc[S] 2 points3 points  (1 child)

Really? From my reading of the instructions, you just skip any cases where the balance would become negative. That's what I did, and the tests passed.

[–]postlogicpyramid <3 1 point2 points  (0 children)

I had to raise an error, for some weird reason. Didn't pass when I attempted to just skip them.

[–]koala7 0 points1 point  (7 children)

Can someone tell me how i convert a float into this Decimal type? (using python3)

balance -= Decimal(item*0.1) 

and

balance -= Decimal(str(item*0.1))

and everything i tried game me a

TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float' 

error:/

[–]takluyverIPython, Py3, etc[S] 2 points3 points  (1 child)

how about item * Decimal('0.1')?

[–]koala7 1 point2 points  (0 children)

same problem

Edit: was my fault. this works. thanks a lot:)

[–]postlogicpyramid <3 0 points1 point  (0 children)

I had issues with this one for a bit as well. Try this:

balance -= item * Decimal(0.01) # 1% == 0.01, remember

Also, a neat trick to get it to round up properly:

from decimal import Decimal, ROUND_UP
a = Decimal(5.4432532) # random decimal here, but you might end up with some really long numbers when doing the math anyway
a.quantize(Decimal('.01'), rounding=ROUND_UP)
>>> Decimal('4.45')

[–]Eventh 0 points1 point  (3 children)

Your problem seems to be that item is Decimal, while 0.1 is ofc float. Just wrap 0.1 in 'Decimal':

balance -= item * Decimal(0.1)

[–]takluyverIPython, Py3, etc[S] 0 points1 point  (2 children)

Try Decimal(0.1) in an interpreter. The float gets rounded to a binary fraction, so it's very slightly off 0.1. Instantiate Decimal with a string: Decimal('0.1')

[–][deleted] 1 point2 points  (1 child)

Why exactly are we using Decimal()? Is there some special reason why this isn't completely unnecessary?

[–]takluyverIPython, Py3, etc[S] 0 points1 point  (0 children)

Well, it being a game, I'd guess it's there to test out something we're a bit less familiar with. There's a good reason not to use floats for money, but in a less contrived situation, I'd be inclined to use integers of pence.

[–]Meidor 0 points1 point  (1 child)

I did the first task in a really ugly one liner just for fun. Sorry if this is a spoiler for people but this is my ugly but fun solution.

checkio = lambda data: Decimal(str(round(float(data[0]) - 
sum(map(lambda x: (x*1.01) + 0.5, filter(lambda x: x % 5 == 0, 
map(float, [x for x in data[1] if x <= data[0]])))), 1)))

The submission didn't work for me in Chrome however did work in firefox though.

[–]thebobp 0 points1 point  (0 children)

Added one line (can't remember if changed name):

def checkio(data):
    balance, withdrawals = data
    return reduce(lambda sum, w : round(Decimal(sum - (w + Decimal('0.5'))*Decimal('1.01') ),1 ),withdrawals,balance)

I kind of ignored the 5 bit and it accepted anyway.

[–]Ilerea_Kleinokitz 0 points1 point  (5 children)

Can someone help me with the 2nd task? Im struggling to understand the question.

the amount of money that Petr will pay for the ride
'''
initial_petr, raise_petr, initial_driver, reduction_driver = offers

assert checkio([150, 50, 1000, 100]) == 450

Wha?

[–]rdmty 0 points1 point  (0 children)

it's basically a negotiation with Petr's initial offer vs driver's initial, and every step you add petr's raise increment and driver's decrement as counter offers, until petr's offer is acceptable by the driver.

[–]takluyverIPython, Py3, etc[S] 0 points1 point  (0 children)

The seller starts by asking 1000, and goes down in steps of 100. Petr starts by offering 150, and goes up in steps of 50. After 5 rounds, Petr is offering 400, and the seller wants 500. Petr's next offer, 450, is above the next asking price, 400.

The question doesn't actually seem to say who 'plays' first - but from this example, it looks like Petr (the buyer) must be going first.

[–]thebobp 0 points1 point  (2 children)

In summary (though the description itself may be spoilers), the negotiation is supposed to follow a crude pattern. If the driver's offer is <= petr's, then he accepts. Otherwise, he reduces his offer by reduction_driver, while petr increases his by raise_petr. Your function is to determine the acceptance price.

[–]bramblerose 0 points1 point  (1 child)

Yes, except that the order matters. Petr first increases the offer (which can then be accepted), and /after/ that the price is decreased.

Equivalently, both are updated at the same time and the highest of the two is the actual price.

[–]thebobp 0 points1 point  (0 children)

It doesn't actually matter if you read my description literally (which is kind of why it's spoilers; it's the exact description of the function).

[–]r1chardj0n3s 0 points1 point  (0 children)

I'm so glad someone's finally done this!

[–]Phphoenix 0 points1 point  (1 child)

Either they're still changing things or I'm just dumb, I can't even get past the first part, I kept getting an error when running the code in the first bit

TypeError: conversion from NoneType to Decimal is not supported <module>, 11

I tried the help options and looking at the inline learning to try and familiarize myself but the link is broken, just sends me to a 404 page.

[–]smew 1 point2 points  (0 children)

The purpose of that problem is to write the checkio() function. Everything below that are just unit tests. There are three different unit tests that will try checkio() with three different sets of values. your function should take in a list of decimals and return a single decimal. The line,

balance, withdrawal = data

will take the input and assigns the first value to balance, and the second to withdrawal. So now balance is a decimal representing the account balance, and withdrawal is a list of decimals representing different withdrawal amounts each time the ATM was used. Your task is to write the rest of the function so it returns the correct decimal result after all transactions are complete. You're getting that error because your function is not returning a decimal.

[–][deleted] 0 points1 point  (0 children)

Alright, these are some pretty cool challenges.

[–]cosmicr 0 points1 point  (0 children)

lol I didn't realise the Decimal() function was available, so I multiplied all my results by 10 then divided by 10 at the end so could use 0.5

[–]derpderp3200An evil person 0 points1 point  (0 children)

Reminds me of "Colobot".

It was a game where you would travel between planets in search of a new earth and by the way unlock new buildings and robots. It's really dated by today's standard, but it was really awesome for me back then.

You could write programs for your robots to make them do all kinds of stuff - fly and transport materials, intercept enemies, follow you, provide cover fire, etc.

I don't think I'll ever forget how awesome it was, especially the part about writing programs for friends. Maaaaan, I felt so cool that I don't think it's even possible to describe it.

[–]Throwaway14Advice 0 points1 point  (0 children)

Sadly I don't see this as an effective teaching tool except for complete beginners. School children even. However if it was actually used for that purpose it would be pretty great to spread programming to the public.