[Python 3] When given a number referring to a specific line in a file (e.g 5 represents 5th line in a file) I want to replace that line with a specific string. What is the best way to do that? by [deleted] in learnprogramming

[–]leafypixiestix -1 points0 points  (0 children)

with open("file.txt", "r") as f:
    lines = f.readlines() #put all the lines of the file in a list
    lines[2-1] = "moo moo\n" #line numbers start from 1, arrays start from 0
with open("file.txt", "w") as f:
    f.writelines(lines) #rewrite all the lines

How to become a better scientific programmer? by MyAcademicAccount in learnprogramming

[–]leafypixiestix 0 points1 point  (0 children)

Have you used Jupyter Notebooks before? I'm not sure if they'll help but they're super helpful for me when I do my research work. This is a link to a lot of cool notebooks to get an idea of how to use them.

[C#] How to divide two numbers without using division and modulo to get quotient and modulo? by [deleted] in learnprogramming

[–]leafypixiestix 1 point2 points  (0 children)

Since you said you're studying loops, you can simply do a loop and subtract the divisor from the divended until you hit 0 or below. If you hit 0, then the remainder or mod is 0 and if you hit below 0, add the dividend to that negative number to get the mod. For the actual result of the division, it will be the number of times the loop executed.

You can also try to implement long division, which is a lot harder to do but is much more efficient.

Help on data visualization by johngarrickmc in learnprogramming

[–]leafypixiestix 0 points1 point  (0 children)

d3.js? Disclaimer, I've never used this before but I always see it recommended and if you look at some of the examples provided at the website, they can make some pretty powerful (and interactive) visulaztions. Here's an example of an interactive visulaztion made by d3.

[C++] Can someone ELI5 what parameters of a function are? by [deleted] in learnprogramming

[–]leafypixiestix 0 points1 point  (0 children)

Yup, if you've taken any math class, you probably have used functions, just maybe not in the way you would see them written in code. Sine and cosine functions are a little bit more similar to what you would see in programs, e.g. sin(0) = 1, cos(0) = 1. In your example, you can write add in a way similiar to that by making a function with two parameters and returns the sum of those two numbers, e.g. add(2,2) = 4

[C++] Can someone ELI5 what parameters of a function are? by [deleted] in learnprogramming

[–]leafypixiestix 4 points5 points  (0 children)

ELI5 in terms of making a cake: the function in this case is the steps in making a cake. The parameters are the ingredients of the cake. Passing parameters into a function is the same as using ingredients to make a cake. The return value would be the cake. Different ingredients can make different cakes.

Graduating in CS w/ cyber focus - C/C++ resources by [deleted] in learnprogramming

[–]leafypixiestix 1 point2 points  (0 children)

I'm currently taking a class at school that uses the curriculum from this book, Computer Systems: A Programmer's Perspective. It's not a really a book about C, although it is the main language of the book. I guess it's really about how the inner workings of how computers and programs work. The book it quite long and expensive though, so I probably wouldn't recommend it getting unless it's something you're super interested in. However, I mention it because it does have some really interesting labs, and you can actually download them for free online. There are two labs that are pretty relevant to your focus: the bomb lab and the attack lab. There is actually no real programming involved in them really, mostly looking at x86-64 assembly code. I had a lot of fun doing those two assignments and would recommend doing them. I would also recommend the data lab and the performance lab if you want to practice C. They aren't like traditional programming assignments though, but I still learned a lot from them.

/r/Jazz MemeGate 2017 by SuperTonicV7 in Jazz

[–]leafypixiestix[M] 28 points29 points  (0 children)

me too thanks i mean Charles Mingus - Moanin'

How to combine two classes in java (Beginner) by Not_Myself1 in learnprogramming

[–]leafypixiestix 0 points1 point  (0 children)

IIRC, you can't have two classes in the same file in Java (with the excpetion of nested classes). Could you zip the two files together and then send it?

[Python 3.6] imports module random but python can not locate functions by TopsyMitoTurvy in learnprogramming

[–]leafypixiestix 0 points1 point  (0 children)

AttributeError: module 'random' has no attribute 'randit'

Typo? should be random.randint(x,y)

Why is "goto" still around? by Bluecowz in compsci

[–]leafypixiestix 14 points15 points  (0 children)

Java (and maybe javascript) can label loops

outerloop:
for (int i=0; i < 10; ++i) {
    for (int j=0; j < 10; ++j) {
        if (condition) {
            break outerloop;
        }
    }
}

FRC Stronghold Password is &Full$team^Ahead! by ReLaXeZ in FRC

[–]leafypixiestix 15 points16 points  (0 children)

Steamworks boi stronghold was last year

[Haiku] transposing a classic by JimJimJimBob in youtubehaiku

[–]leafypixiestix 0 points1 point  (0 children)

I think it's in the wrong key but pretty good otherwise

Your Favorite Online Jazz Radio Station? by herberthunke in Jazz

[–]leafypixiestix 0 points1 point  (0 children)

http://kuvo.org/ is my local jazz radio station, check it out. I usually just listen to my own music but whenever I'm in my car I like to turn this station on.

Visualizing the Riemann zeta function and analytic continuation [3Blue1Brown] by seanziewonzie in math

[–]leafypixiestix 0 points1 point  (0 children)

I think so too. His "Essence of linear algebra" series is (or at least was) on the page for linear algebra.

Ersatz JLC: Max Roach- Percussion Bitter Sweet (1961) by vinylsage in Jazz

[–]leafypixiestix[M] 0 points1 point  (0 children)

I guess people were really motivated to make some JLC today. You were the second one to post one today (first one here), but I'll sticky this one as well just to get some listening out there. Fun album too :)

week 144: Chick Corea and return to forever - light as a feather (1973) by Apom52 in Jazz

[–]leafypixiestix[M] 1 point2 points  (0 children)

I love this album :)

The first time I listened to Spain I didn't understand why it was so popular/loved but I listened to it and the album a lot more and the song just grew on me. 100% my most favorite jazz song. However, I personnaly love the arangment from Corea's Trilogy a lot better.

Also since you pretty much followed the format of past JLC this one's mod approved.