[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

In little over 24 hours I have an assignment due for Intro to

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 40
Thread images: 8

File: teherb4y.png (80KB, 1000x1000px) Image search: [Google]
teherb4y.png
80KB, 1000x1000px
In little over 24 hours I have an assignment due for Intro to Programming using python.

Looking for quick answers, assistance understanding pseudo code and possible future tutoring.

Able to pay, hoping to exchange between Discord or Skype.
>>
Post the criteria, I might give it a whirl.
>>
File: huihui7.png (4KB, 343x119px) Image search: [Google]
huihui7.png
4KB, 343x119px
>>230375
I'll see if I can get a clear photo. The only light in my apartment is my monitor. I'll leave one of the quick answers here for now.
>>
File: huihui7.png (936KB, 959x515px) Image search: [Google]
huihui7.png
936KB, 959x515px
>>230375
>>
Ok I see it, give me a little bit, only used python once, so gotta learn the syntax real quick and grab a good IDE. I'll comment the shit out of it when I'm done so you can understand what's going on
>>
>>230401
I appreciate it!

I learn best from example and imitating something similar on my own and the textbook I bought is only a list of instructions.

Community college bites I tell ya.
>>
Going to bump once before I fall asleep.
>>
>>230426
I'm still here btw, almost done with the program, I just gotta figure out how to check next/previous values in that pusedocode
>>
>>230401

>IDE

Into the trash it goes.

>>230372

Go to the site and spend literally one hour reading the first three chapters of the introduction manual. Everything you posted can be solved easily with what's there.
>>
>>230432
yeah I realized my mistake as soon as I posted that, mb
>>
>>230426
https://repl.it/Ef5N/4
Should be able to understand whats going on from my comments. Formatting isn't beautiful but it works and is understandable.

>>230379
answer is true btw, you can always append/delete values
>>
>>230444
You can't peek in a foreach, that's not what they're for. Good job wasting OP's time challenging him to do something that can't be done.
>>
>>230444

Thank you very much - you're a life saver.
>>
>>230460
oh I didn't know, my bad, I don't have much python experience. Is there a more efficient way to do it than the way I did it though?
>>
File: huihui7.png (21KB, 806x609px) Image search: [Google]
huihui7.png
21KB, 806x609px
>>230662
The program runs well enough to get a grade for it, but there are two fixes that'll get the A.

All the results could show on a single line, and parenthesis only appear on a run before the 6th roll. I edited the code to be a D6 I'll post that third.
>>
File: huihui8.png (876B, 32x357px) Image search: [Google]
huihui8.png
876B, 32x357px
>>230677
>>
File: huihui7.png (14KB, 618x526px) Image search: [Google]
huihui7.png
14KB, 618x526px
>>230677
My edit.
>>
>>230662
Not really: you're constrained to inplementing the algorithm as described, and the algorithm as described isn't really very pythonny.

In python 2.x you need to use xrange() otherwise it actually constructs the range in memory then iterates it. So for i in range(0,1000000) is not a good idea. Python 3 range behaves like xrange.

If you were actually doing this in Python, the entire pseudocode goven could be replaced by a one-liner regular expression replace.
>>
>>230691
That's my problem with the assignment as a whole, I HAD to use the pseudo code even if there was a more simple way to do it.
>>
File: results.png (186KB, 1599x861px) Image search: [Google]
results.png
186KB, 1599x861px
>>230681
I am unable to reproduce the paren error, looks like they are all there for me. Single line might be something to look into. The most obvious way that I can think of is store the numbers and paren in a list and print that? That might stray quite a bit from the pusedocode though
>>
>>230696
Really your assignment needs updated. That's a C assignment with "C" scratched out and "Python" written in.
>>
>>230697
I found the parenthesis error. I'll look around to help on the print one line issue.

Would anyone be available for list manipulation? I can do much of it on my own but some language I don't know.
>>
>>230704
Use sys.stdout.write instead of print, and use a "\n" whenever you need a newline.

You should probly call sys.stdout.flush(), but it'll get flushed when your program terminates, so no biggie.

I would say "build a string and print that", but rule 1 is "implement the algorithm as written, no matter how retarded it is".
>>
>>230704
python 3 lets you print("some string", end=""), but python 2 doesn't unless you use a "from future" line.
>>
>>230691
Oh, and just to put my money where my mouth is:

import random; import re; print re.sub("(([\d])\\2+)","(\g<1>)",''.join([str(random.randrange(0,6,1)) for _ in range(20)]))


But it's more legible as

import random
import re
rolls=[str(random.randrange(0,6,1)) for _ in range(20)]
rollstring=''.join(rolls)
result = re.sub("(([\d])\\2+)","(\g<1>)",rollstring)
print result
>>
File: IMG_0268.jpg (92KB, 954x310px) Image search: [Google]
IMG_0268.jpg
92KB, 954x310px
Very last one.

I can hook someone up through paypal if everything checks out.
>>
>>230765
#!/usr/bin/env python
import string
values=[float(i) for i in (string.split(raw_input('Please enter the values, separated by spaces: ')))]
scale=40/max(values)
for i in values:
____print "*"*int(i*scale)

Obviously, replace ____ with four spaces.

>I can hook someone up through paypal if everything checks out.
If you feel like giving away money, give some to Anthony Nolan or the National Marrow Donor Program.
>>
>>230841
Could I see that in repl.it please?
>>
>>230833
https://repl.it/Efpb/4

I made it so the amount of inputs is static, hopefully thats fine. Follow instructions at bottom to get more/less inputs
>>
>>230853
Sure.
https://repl.it/EfqR/0

>>230857
>https://repl.it/Efpb/4
heh.
>>
>>230857
To elaborate, you didn't read the question right. The inputs are totally allowed to be over 40; you're meant to scale them yourself so that the biggest one gets 40 *s, and the rest get less, proportionally.
>>
>>230857
wait fuck I did it wrong, don't look at this one
>>
>>230857
Also stuff like
>Follow instructions at bottom to get more/less inputs
This is exactly what the "for x in y" construct is for: you loop over all the items in the list, whatever size the list is.
>>
>>230869
I got this.
https://repl.it/EfqR/0
>>
>>230872
Looks good! Thanks for coming through on my inability to follow instructions, I'll just see myself out now Q_Q
>>
>>230872
This is pretty fantastic, but I think my instructor would catch wind that I didn't write that pretty fast.
>>
>>230887
Sure. But now you can write something that works the same but is a little more verbose, right?

You said up above you learn best by example; you just saw some examples of splitting strings, using a list comprehension to do something to every item in a list, using the library to find a maximum value in a list, casting things to floats and strings, and multiplying strings by ints.

A good starting point would be replacing the [x for i in y] construct at the end with a more conventional "for i in y:" loop: it was only like that to avoid having to use indentation (which 4chan mangles).
>>
>>230891
>https://repl.it/EfqR/0
Yeah I'll be looking it over and paraphrasing it in my own way. Taking a brief break right now though, half killed myself with stress on the main portion of the assignment.
>>
>>230857
I used your code as a template to make what the teacher would believe.
>>
Janitor can sweep this thread.

Thanks a ton everyone!
Thread posts: 40
Thread images: 8


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.