• Breaking News

    Monday, February 7, 2022

    Learn Python the Hard Way exercise 33 loop question Ask Programming

    Learn Python the Hard Way exercise 33 loop question Ask Programming


    Learn Python the Hard Way exercise 33 loop question

    Posted: 07 Feb 2022 01:20 AM PST

    Hello, I was working on LPTHW by Zed Shaw doing the following exercise:

    i = 0 numbers = [] while i < 6: print(f"At the top i is {i}") numbers.append(i) i = i + 1 print("Numbers now: ", numbers) print(f"At the bottom i is {i}") print("The numbers: ") for num in numbers: print(num) 

    Since the program spits out lists with increasing amounts of elements I, naturally, wanted to make some pretty triangles. Like this:

    Numbers now: [0] Numbers now: [0, 1] Numbers now: [0, 1, 2] Numbers now: [0, 1, 2, 3] Numbers now: [0, 1, 2, 3, 4] Numbers now: [0, 1, 2, 3, 4, 5] Numbers now: [0, 1, 2, 3, 4, 5, 6] Numbers now: [0, 1, 2, 3, 4, 5, 6, 7] Numbers now: [0, 1, 2, 3, 4, 5, 6, 7, 8] Numbers now: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Numbers now: [0, 1, 2, 3, 4, 5, 6, 7, 8] Numbers now: [0, 1, 2, 3, 4, 5, 6, 7] Numbers now: [0, 1, 2, 3, 4, 5, 6] Numbers now: [0, 1, 2, 3, 4, 5] Numbers now: [0, 1, 2, 3, 4] Numbers now: [0, 1, 2, 3] Numbers now: [0, 1, 2] Numbers now: [0, 1] Numbers now: [0] Numbers now: [] 

    So I spent a lot of time writing this code:

    def triangles(max_number, increment, decrement): i = 0 numbers = [] while i < max_number: numbers.append(i) print(f"Numbers now: {numbers}") i = i + increment if i == max_number: while i > 0: numbers.pop() print(f"Numbers now: {numbers}") i = i - decrement if i == 0: break choose_num = int(input("Choose a number:\n")) choose_increment = int(input("Choose a number to increment:\n")) choose_decrement = int(input("Choose a number to decrease:\n")) triangles(choose_num, choose_increment, choose_decrement) 

    But there is just one thing that keeps bugging me:

    Numbers now: [] 

    This last list comes out empty and I cannot figure out why, and it's killing me that it's not symmetrical.

    I'm sure I'm not using the for and whiles correctly but this is what seemed to work after a while.

    I would appreciate it if someone could help me get rid of that empty list at the end.

    Thank you :)

    submitted by /u/keni98
    [link] [comments]

    Recursively finding all childrens?

    Posted: 06 Feb 2022 09:31 PM PST

    Hello I am coding a simple project in c++ and I am very bad with visualizing recursion. Can someone help me?

    I have a set of children indexes.

    So children[id] = { set of children for given id }

    I want to recursively find all children of id. However there can be multiple levels so I need to do it recursively.

    Example:

    Parent | Child

    2 | 3, 4, 10

    4 | 5, 6, 7, 8

    8 | 9

    If I want to find all child of 2, it should be: 3, 4, 5, 6, 7, 8, 10 (because it includes those children of 4)

    My current code:

    set<int> recurse(int index) { set<int> answer; set<int> childrenofIndex = getChildren(index) for (loop through each children as c) { set<int> childOfChild = getChildren(c); answer.insert([I am stuck here]); // What should I do? I am getting back another set from getChildren(c), but if I were to loop it again then I essentially need to keep looping through and it is never ending. } } 
    submitted by /u/halppweaseee
    [link] [comments]

    How t memoize this Recursion

    Posted: 06 Feb 2022 11:53 PM PST

    I have tried to memoize this code by storing the value before the return in the base case and before the last return statement by all my dp matrix at the end contains only one value at the [0][0] index which is the final answer. Can you please help to memoize this. Thanks in advance

    def knapsack01(wtArray, profitArray, maxWt, wt=0, profit=0, idx=0): if(idx == len(wtArray)): if(wt<=maxWt): return profit return -1 return max(knapsack01(wtArray, profitArray, maxWt, wt+wtArray[idx], profit + profitArray[idx], idx+1), knapsack01(wtArray, profitArray, maxWt, wt, profit, idx+1)) 
    submitted by /u/Equal-Caregiver3382
    [link] [comments]

    Help creating program that plays audio files at random from a collection of 20+ TB. (Music)

    Posted: 06 Feb 2022 11:17 PM PST

    Hello,

    I really love music, and for a while now, I have been using VLC media player to dump all my music folders and have them play at random. What's inconvenient is that VLC doesn't automatically open every album folder and never really goes through each album.

    I would really like help/suggestions for playing a large amount of audio files ranging from FLAC/WAV/MP3 in a complete random order.

    Is it possible to connect something like a raspberry pi to a high capacity drive, with some kind of open source media player that can really go through a large collection at random?

    Thank you.

    submitted by /u/No_Coach7599
    [link] [comments]

    Regarding Competitive Programming

    Posted: 07 Feb 2022 12:50 AM PST

    Should I start Competitive Programming- It seems like a difficult task as every question I try to solve is too difficult. What resources or approach would you recommend to me?

    submitted by /u/JustDoIt_boy
    [link] [comments]

    A very basic question

    Posted: 06 Feb 2022 08:48 PM PST

    Hello all,

    I am trying to self-learn a programming language. Very often while writing code, I find myself trying to write a bunch of semi-complex code(with several classes, functions etc.) from the top of my head. Kind of like I am typing this post.

    It ends up in making me confused, forgetting or missing out on important bits of code that should have been there.

    Clearly, there must exist an intermediate step between idea/thoughts and actual writing of code. It is obvious to me that anything complex for real world implementation must have something more than typing from your thoughts, like planning which all classes and functions need to be created, names, objective sof each etc.

    Is there such a thing/process which I can follow? Many thanks.

    submitted by /u/TyrannosaurWrecks
    [link] [comments]

    User authentication derby dB

    Posted: 07 Feb 2022 03:32 AM PST

    Hi guys, I am making a java web application for a college project. I have a JSP page that stores customer details upon successful registration.

    <%@page contentType="text/html" pageEncoding="UTF-8"%>

    <%@page import="java.sql.*,java.util.*" %>

    <% Class.forName("org.apache.derby.jdbc.ClientDriver");%>

    <%

    //using get parameter to get values from index.jsp

    String fn=request.getParameter("firstname");

    String ln=request.getParameter("lastname");

    String ad=request.getParameter("address");

    String em=request.getParameter("email");

    String ph=request.getParameter("phone");

    String ps=request.getParameter("password");

    String conps=request.getParameter("confirmpass");

    //connecting to dB

    Connection conn=DriverManager.getConnection("jdbc:derby://localhost:1527/register","john","321");

    Statement st=conn.createStatement();

    //inserting values into dB

    int i=st.executeUpdate("insert into register values('"+fn+"','"+ln+"','"+ad+"','"+em+"','"+ph+"','"+ps+"','"+conps+"')");

    This is my code for storing the customers details. I have a seperate JSP page called Login where I want to check the dB for existing details before allowing access to the site. Anything I have found online has either not worked / made little sense. Can someone help me please.

    submitted by /u/Apprehensive-Rain-91
    [link] [comments]

    Desktop development in 2022?

    Posted: 06 Feb 2022 08:12 AM PST

    Precursor: I googled this first and came up with crap results.

    Question: what's a good language/environment for developing desktop apps these days?

    My primary need is windows, but cross platform would of course be nice.

    I did some development 15 years ago, back then borland delphi was nice in that it could compile to a stand alone exe with all the dependencies baked in. MS had 'winforms' with C# or VB but those apps required installers.

    Just wondering what the landscape looks like today for someone trying to build a simple desktop app

    submitted by /u/JacksReditAccount
    [link] [comments]

    I need help creating a study program to become a web developer.

    Posted: 06 Feb 2022 09:02 PM PST

    I know there are resources like the Odin project. But I would like to know with more accuracy what kind of skills and knowledge do I need to do freelance web developing jobs or to land a remote job, which resource to learn each of those skills and in which order to learn them. It's not like if I finish the Odin project I'm going to be landing a job just by saying I finished it right ? So what else is and what kind of skills do I need to learn.

    TLDR; In general I would like to make a list in chronological order of all the things I need to learn and where to learn them from.

    submitted by /u/ProjectAioros
    [link] [comments]

    X509_STORE_add_cert:cert already in hash table error?

    Posted: 06 Feb 2022 03:17 PM PST

    Hi there, I have an certificate store written in C++ implemented w/ openssl and when loading certificates, I keep getting the message: `X509_STORE_add_cert:cert already in hash table`. What is the "hash table" in this context/ does this mean the cert has already been loaded? I'm confused as I don't believe anything has been loaded/don't know of a way to check. I can't seem to find much documentation online on what this error means.

    submitted by /u/Outrageous-Pool7077
    [link] [comments]

    Easiest process to alter a simple string? (open to any language)

    Posted: 06 Feb 2022 04:18 PM PST

    Hi all!

    I have a very specific task I'm trying to do and attempting to figure out where the best place to even start is (i have basically no coding experience). Essentially, I'm extracting data from one database that's in one format, and then need to update it into another format. Ideally, I would just want to copy/paste the initial data, run this script (or even do something in a google sheet?) and have it spit back out as text in the new format.

    The data would be entered in this format:

    - Task Name @estimate(15m) @defer(2022-01-02 00:00) @due(2022-02-10 00:00) 

    And then I'd want it exported in this format:

    Task Name ( for 15m due 2022-02-10 00:00 not before 2022-01-02 00:00 ) 

    My (very basic) understanding is I would want to set the task name, estimate, defer date, and due date is variables using the first string, and then just use those values to fill in the second string. I have very little experience trying to do something like this, so any pointers or tips are appreciated.

    Thanks!

    submitted by /u/hungrytako
    [link] [comments]

    Looking for vs code assistance.

    Posted: 06 Feb 2022 06:19 PM PST

    Been trying to set up vs code on a new workstation for hours now and cannot seem to get it right. YouTube guides have been helpful but even after following them I am unable to run programs the same way they do.

    I've installed VS code, C++ and coderunner extensions, gcc g++ and gdb, and even created a new executable command in the tasks.json folder as instructed.

    When I go to run a simple hello world program I receive an error message telling me that no such file or directory exists and that it was terminated. Similarly when I try to compile and execute using g++ in both powershell and wsl terminals I receive fatal errors.

    I have attached a few screenshots here for reference. I don't understand why I am incapable of setting up the program. Thanks for any help you can provide.

    Screenshots: https://imgur.com/a/gdsabLl

    submitted by /u/kymeklmraiden
    [link] [comments]

    What would you do with a terabyte of RAM?

    Posted: 05 Feb 2022 10:15 PM PST

    So I impulse bought an old refurbished server with 1TB of RAM and am desperate to come up with a project to put all those DIMMs to work. What's an idea you would explore or a project you would build if only you had that much RAM?

    submitted by /u/neuromancering
    [link] [comments]

    How do you find contracting work?

    Posted: 06 Feb 2022 09:17 AM PST

    I'm interested in contracting but not really sure how people get in contact to become contractors. Is it usually through recruiters, clients, or some online site like LinkedIn for finding contracting work?

    submitted by /u/WickedSlice13
    [link] [comments]

    Turn spreadsheets into a webpage?

    Posted: 06 Feb 2022 12:45 PM PST

    I'd like to create a website which basically has the same design and functionality as a bookkeeping spreadsheet that I have on excel. Each user would have their own login and save their info.

    I don't know where to start, what programming languages should I be looking at?

    submitted by /u/Hot_Job6182
    [link] [comments]

    CSV to JSON Woes (...AND StackOverflow is DOWN!)

    Posted: 06 Feb 2022 03:16 PM PST

    So I'm currently seeing the limitation to CSV, but I don't really have a choice. This is a project I'm doing for my brother who owns a little shop nearby. He wants to host a digital menu in-store for his customers. He wants to use a spreadsheet to maintain the data and then I then parse that CSV into JSON and render elements via Handlebars.js to a page.

    The basic idea is that for each brandName I'm creating a <widget> and for each product with said brandName, I'm nesting <accordion> elements inside. Here's the general idea: https://imgur.com/XmDzPJ9

    Cool, but I've been working with dummy data in desired JSON output. This doesn't jive with the actual output from the CSV file.

    This is the desired output:

    [ { "brandName": "ABC", "products": [ { "productName": "Product 1", "qty": 1, "description": "This is a description." }, { "productName": "Product 2", "qty": 2, "description": "This is a description." }, { "productName": "Product 3", "qty": 3, "description": "This is a description." } ] }, { "brandName": "Blue Co.", "products": [ { "productName": "Product 4", "qty": 4, "description": "This is a description." }, { "productName": "Product 5", "qty": 5, "description": "This is a description." } ] }, { "brandName": "Red Co.", "products": [ { "productName": "Product 6", "qty": 6, "description": "This is a description." } ] }, { "brandName": "XYZ", "products": [ { "productName": "Product 7", "qty": 7, "description": "This is a description." }, { "productName": "Product 8", "qty": 8, "description": "This is a description." } ] } ] 

    This is what the CSV (via Google Sheets) actually looks like: https://imgur.com/OUjw7Zu

    This is the actual output converted to JSON:

    [ { "brandName": "ABC", "productName": "Product 1", "qty": 1, "description": "This is a description." }, { "brandName": "ABC", "productName": "Product 2", "qty": 2, "description": "This is a description." }, { "brandName": "ABC", "productName": "Product 3", "qty": 3, "description": "This is a description." }, { "brandName": "Blue Co.", "productName": "Product 4", "qty": 4, "description": "This is a description." }, { "brandName": "Blue Co.", "productName": "Product 5", "qty": 5, "description": "This is a description." }, { "brandName": "Red Co.", "productName": "Product 6", "qty": 6, "description": "This is a description." }, { "brandName": "XYZ", "productName": "Product 7", "qty": 7, "description": "This is a description." }, { "brandName": "XYZ", "productName": "Product 8", "qty": 8, "description": "This is a description." } ] 

    So, I'm genuinely just not sure what step to take with this. Handlebars is working well when I use my ideal JSON, creating <widgets> for each of my brandNames, but as you can see the result of the CSV -> JSON is different and I can't use {{#each}} to pull the right values in.

    Any ideas would be appreciated. I feel like I am both underthinking and overthinking this...

    submitted by /u/muscles4bones
    [link] [comments]

    28 and just starting

    Posted: 06 Feb 2022 03:39 AM PST

    I've always been interested in programming, until recently I decided to really give it a try and started doing some python courses.

    The issue is that it makes me a little anxious to be starting at this age, without previous experience or studies, all that makes it a little hard to concentrate. So, do you see it possible to become a good programmer?And how many years should I expect to be comfortable/fluent.

    I know very well that there are a thousand variants and that everything depends on itself, but I would love to read your thoughts.

    submitted by /u/Greeford
    [link] [comments]

    I need some help with VB6!

    Posted: 06 Feb 2022 04:50 AM PST

    I have a picturebox, what is checking the webcam always, whenever i push my desired button, it should save a pic. Everything works, except that, the pics are always blank.

    Private Sub Command5_Click()

    Picture1.AutoRedraw = True

    Picture1.Picture = Picture1.Image

    SavePicture Picture1.Picture, App.Path & ("/" & Text1) & ".bmp"

    File1.Refresh

    End Sub

    submitted by /u/ben_aloha
    [link] [comments]

    Why do some companies use Bitbucket over GitHub?

    Posted: 06 Feb 2022 08:31 AM PST

    Thank you!

    submitted by /u/madarreggel
    [link] [comments]

    Java coding challenge, unsure how they want to interact with the code

    Posted: 06 Feb 2022 06:27 AM PST

    I was given a coding challenge to evaluate if I was fit for a role at a company, I have completed all their challenges and now I am stumpt at what should be the easiest part.

    They ask me to submit the source code along with the instructions on how to run it. When they say "instructions on how to run it" I dont understand what they expect from me, do they want me to tell them to copy each function into the main method with their desired input or to create some sort of command line allowing them to interact with it?

    submitted by /u/DontBeSnide
    [link] [comments]

    Solidity as first language?

    Posted: 06 Feb 2022 03:46 AM PST

    It is posible, to start learning code solidity as my first language?

    submitted by /u/Greeford
    [link] [comments]

    What to do if company assigned me a less qualified mentor

    Posted: 06 Feb 2022 05:03 AM PST

    I've been working on this project for a couple of months now as a junior developer. As it turned out by now, besides having more work experience than me, my mentor is not able to mentor me (and the other juniors who used to reach out for help to me, not him), could not properly anwer my questions even once. His code is hard to test and maintain (so I have to sercetly refactor it sometimes). I like working on this project, but it is fustrating that he is the one who directly gives me instructions and probably earns much more money than me.

    submitted by /u/demiert
    [link] [comments]

    Can you pass an operating systems course without any knowledge of computer architecture?

    Posted: 06 Feb 2022 08:34 AM PST

    University course. There is no prerequisites list, or at least I couldn't find it. Sorry if it's a dumb question, but I can't tell if it is because I don't know much about either course. Thank you!

    submitted by /u/madarreggel
    [link] [comments]

    i want to start learning about data structures and algorithms, what language is the most common for that?

    Posted: 06 Feb 2022 08:34 AM PST

    thank you!

    submitted by /u/wolfakix
    [link] [comments]

    How do I start on creating a node based audio routing program?

    Posted: 06 Feb 2022 04:10 AM PST

    A program like voicemeeter that can work with all audio APIs. But the routing is handled in a node based format like a VST host. Where do I start?

    submitted by /u/DeconThe1
    [link] [comments]

    No comments:

    Post a Comment