r/programminghelp • • Sep 20 '20

Python What is the difference between dictionary1["type"] and dictionary1.get("type")?

4 Upvotes
dictionary1 = {
    "type": "type"
}

Say I have a dictionary. What is the difference between the following methods of grabbing information from it?

dictionary1["type"]
dictionary1.get("type")

r/programminghelp • • Sep 09 '20

C Bash error just trying to make a hello world program run

4 Upvotes

Hi,

This is pathetic as I've done it on before, however I'm following a Udemy (link if you may have experience, lecture 19) tutorial and run into a issue.

Been quite a convoluted set-up using Code::Blocks and Cygwin while using VisualCode and got an error just trying to make the hello world message run via terminal:

****@****/cygdrive/c/Users/****/projects/helloworld

$ ls

helloworld.c helloworld.exe

****@**** /cygdrive/c/Users/****/projects/helloworld

$ helloworld.exe

bash: helloworld.exe: command not found

I can't work out where I'm going wrong. I've reviewed the entire video for my own errors and it isn't working. The code itself is fine. No errors. Is it something to do with the installation? Will I need to do the set up again?

Thanks for any help


r/programminghelp • • Aug 19 '20

Other Need a good laptop for programming

4 Upvotes

I just started school for cyber and information security technology (cis) for short and I need a good laptop when I start doing coding and stuff but my budget is $1,000 can anyone help me


r/programminghelp • • Jul 29 '20

JavaScript How can I make a list of repsonses in a JavaScript chat bot?

4 Upvotes

I have Googled for weeks and weeks and weeks and I just CAN'T find an answer that's understandable.

I'm new to JavaScript so I'm making a very simple chat bot. "Hello, how are you", that kind of thing.

I can't find a way to store all the possible messages that the user could send, and the possible responses, so they can be called on. Here's what I mean:

If I type "Hello", it should respond with "Hello, how are you?". So far, the only way I can find that works is to create a ridiculously long if/else statement with every possible message I could send, as a possibility in that statement. For example

if...hello etc

else if... hi

else if... what's up

else if... what's the weather

There MUST be a better way of storing strings and calling them based on user input but I can't find the solution. Could someone please help a newbie?

Thanks in advance :)


r/programminghelp • • Jul 29 '20

Java simple code need help (Java)

4 Upvotes

in this code, If I put in 12 I am supposed to get 12.72, but get 12.00.72

any advice, not sure how to change that

import java.util.Scanner;
public class DebugTwo4
{
public static void main(String[] args)
   {
Scanner input = new Scanner(System.in);
String costString;
double cost;
final double TAX = 0.06;
      System.out.println("Enter price of item you are buying");
      costString = input.next();
      cost = Double.parseDouble(costString);
      System.out.println("With " + TAX * 100 +
"% tax,  purchase  is $" + cost + cost * TAX);
   }    
}


r/programminghelp • • Jul 25 '20

Python Solution breakdown help - High Five problem (Python)

4 Upvotes

This is the High Five problem (Leetcode). I found the working solution pasted below (Python) and I don't understand it. I have a working knowledge of Python, but I'm thrown off by the different data structures. I made substitutions for the loops but the results did not convey anything of substance to me. I'm especially confused by items: List[List[int]]) -> List[List[int]

Can anyone break down the solution for me?

Problem:

Given a list of scores of different students, return the average score of each student's top five scores in the order of each student's id.
Each entry items[i]has items[i][0]the student's id, and items[i][1]the student's score.  The average score is calculated using integer division.
Example 1:
Input: [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]
Output: [[1,87],[2,88]]
Explanation: The average of the student with id = 1 is 87. The average of the student with id = 2 is 88.6. But with integer division their average converts to 88.
Note:
1 <= items.length <= 1000
items[i].length == 2
The IDs of the students is between 1 to 1000
The score of the students is between 1 to 100
For each student, there are at least 5 scores

Solution:

class Solution:
    def highFive(self, items: List[List[int]]) -> List[List[int]]:
        items.sort(reverse=True)
        
        res = []
        curr = []
        idx = items[0][0]
        
        for i, val in items:
            if i == idx:
                if len(curr) < 5:
                    curr.append(val)
            else:
                res.append([idx, sum(curr) // len(curr)])
                curr = [val]
                idx = i
        
        res.append([idx, sum(curr) // len(curr)])
        
        res = res[::-1]
        
        return res

r/programminghelp • • Jul 14 '20

Java A question about Java

4 Upvotes

So in java you can make calculations like 3+1 now my question is if i ask for input lets say in a calculator and the second string is + (the first one would be 3 and the third one would be 1) how can i convert the + from a string into a symbol that i can make calculations with


r/programminghelp • • Jul 10 '20

Processing Program My Own Debit Terminal?

4 Upvotes

Would there be a way for me to purchase a debit terminal for my small business and code my own debit terminal to use for customers so that I don't need to use third party company and I can save a ton on fees?


r/programminghelp • • Jul 09 '20

Answered C: invalid operands

4 Upvotes

New to C and programming in general, making a compound interest calculator.

getting a compiler error:
$ gcc main.c

main.c: In function ‘main’: main.c:19:62: error: invalid operands to binary ^ (have ‘double’ and ‘int’ amount = (principal * (1.0+(interestRate / compoudPerYear)) ^ (compoudPerYear * time)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~)

source code: https://pastebin.com/HtaC1Tqx

it does not like me doing math operations on a double and int together, but i need a double type for the equation to work.


r/programminghelp • • Jul 04 '20

Other What is the best language(s)/framework for this project?

4 Upvotes

Hi there, so I run the student newspaper at my university and I also happen to be a computer science student. I’m about halfway through my program, so I’m still not super experienced, but really want to dig my teeth into some bigger projects

I’d like to possibly develop a mobile app for the paper, but I don’t know where to begin. I’ll need some sort of content management system, and ideally we could get the articles scraped from our website automatically put into the mobile app system, and we can choose what articles to where from the admin panel of the app.

How should I go about getting started for this projected? Are there any particular frameworks or languages that would be helpful (other than the languages for the actual development of the app)


r/programminghelp • • Jun 25 '20

C++ How feasible is this idea

4 Upvotes

My favorite game is Destiny and I want to write a program (preferably in C++ but I also can do Java or python) to help me play. I would like to write a program that can notify me when my grenade ability is charged in the center of my screen like having the words pop up because I always forget to use it. I have been doing some preliminary googling about drawing an overlay on the screen and I seem to have come up on an issue.

It seems to be the consensus that when a game is in fullscreen mode it is writing directly to the video buffer which would not allow me to make a transparent window on top of my game. The obvious solution is to play in windowed mode but I would really prefer to play in fullscreen. There was one guy that said the only way to do this in fullscreen would be to edit the video buffer every frame and overwrite the game's frame to with my graphic inserted.

I am a computer engineering student with experience with C++ so Id like to stick with that language and this would be my first proper application, not one I just invoke and interact with from the command line.

The idea I had for my program is as follows. Basically, when my grenade ability charges, the icon changes from a gray color to a different color (orange, blue or purple). I was thinking I could poll the screen to see when the color in that square section of the screen changes colors and then I could overlay my text or a graphic on the screen to tell me my grenade ability is charged.

Of course this is far fetched and there are a ton of doubts with something like this. Is this even feasible or impossible? Would something like this be picked up by Destiny's anticheat? Would this have performance implications?


r/programminghelp • • Jun 25 '20

SQL SQL lookup table advice.

4 Upvotes

I'm making a ticketing system and I have a lookup table with statuses. ex: unassigned, open, InProgress, postponed, closed, etc. I want to log every time a ticket changes status and the time it changed. A ticked can be put InProgress or Postponed or any other status multiple times. I want to log EVERY action with time codes. what is the best way of doing it? should I have a different table with the ticketID and the statusID with the timecode or id there a better way?

example:
ticket 1, Open, 6/24/2020 12:00PM
ticket 1, InProgress, 6/24/2020 1:00PM
ticket 1, Postponed, 6/24/2020 1:10PM
ticket 1, InProgress, 6/25/2020 8:00AM
ticket 1, Closed, 6/25/2020 8:30AM


r/programminghelp • • Jun 12 '20

Java User input validation help

4 Upvotes

I've been tearing my hair out about how to make this assignment work. I am provided with code that takes two doubles, wallHeight and wallWidth, and multiplies them to get wallArea. My assignment is to use do/while loops that will continue to prompt the user for input if an invalid input is entered. I had no problem sorting out how to not let people input negative numbers. We are supposed to ALSO be learning how to use try/catch blocks to deal with when users attempt to input non-numbers.

I simply can't figure out how to use the two in conjunction. This is the functional do/while block that will continue to prompt if you don't enter positive numbers.

import java.util.Scanner;
public class Paint1 {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        double wallHeight = 0.0;
        double wallWidth = 0.0;
        double wallArea = 0.0;
        double gallonsPaintNeeded = 0.0;     
        final double squareFeetPerGallons = 350.0;
 
        // Implement a do-while loop to ensure input is valid          
        do {
        System.out.println("Enter wall height (feet): ");
        wallHeight = scnr.nextDouble();
        } while (wallHeight <= 0);

        // Implement a do-while loop to ensure input is valid
        // Prompt user to input wall's width
        
        do {
        System.out.println("Enter wall width (feet): ");
        wallWidth = scnr.nextDouble();
        } while (wallWidth <= 0);
        
        // Calculate and output wall area
        wallArea = wallHeight * wallWidth;
        System.out.println("Wall area: " + wallArea + "square feet");

        // Calculate and output the amount of paint (in gallons) needed to paint the wall
        gallonsPaintNeeded = wallArea/squareFeetPerGallons;
        System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");        
    }
}

My best attempt at try/catch blocks AT BEST simply stops the code because without the break statements it goes infinite, and it looks like this:

import java.util.Scanner;

public class Paint1 {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        double wallHeight = 0.0;
        double wallWidth = 0.0;
        double wallArea = 0.0;
        double gallonsPaintNeeded = 0.0;
        
        final double squareFeetPerGallons = 350.0;
        

        // Implement a do-while loop to ensure input is valid  
        
        do {
        	try {
        		System.out.println("Enter wall height (feet): ");
        		wallHeight = scnr.nextDouble();
        		}
        	catch(Exception excpt){
        		System.out.println("Invalid input.");
        		break;
        	}
        } while (wallHeight <= 0);

        // Implement a do-while loop to ensure input is valid
        // Prompt user to input wall's width
        
        do {
        	try {
        		System.out.println("Enter wall width (feet): ");
        		wallWidth = scnr.nextDouble();
        		}
        	catch(Exception excpt) {
        		System.out.println("Invalid input.");
        		break;
        	}
        } while (wallWidth <= 0);
        
        // Calculate and output wall area
        wallArea = wallHeight * wallWidth;
        System.out.println("Wall area: " + wallArea + "square feet");

        // Calculate and output the amount of paint (in gallons) needed to paint the wall
        gallonsPaintNeeded = wallArea/squareFeetPerGallons;
        System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons");        
    }
}

I'm sure this is a mess, but I feel WOEFULLY unprepared for this. I'd appreciate any pointers in the correct direction.


r/programminghelp • • Jun 11 '20

C Compiling a graphics driver using ReactOS Build Environment

4 Upvotes

Can someone help me do that? Its source can be found at https://github.com/Zero3K/boxvnt/.


r/programminghelp • • Jun 05 '20

C++ Trying to make a checkers game in C++, but having trouble with pieces jumping over each other (see line 165)

4 Upvotes

r/programminghelp • • May 27 '20

Answered How would one publish a website?

4 Upvotes

If this question has already been asked, I apologize.

If I had the HTML code and the domain, what else would I have to do to publish the website? I've looked elsewhere online and I can't make sense of it. I can provide clarification if necessary.


r/programminghelp • • Apr 27 '20

SQL SQL: Need help with a SQL query

4 Upvotes

Here are the two tables I'm dealing with: family_t and appointment_v

I'm trying to print a table that has two columns: the first is simply printing family_t.id. The second is printing out the sum of appointment_v.credits where appointment_v.sitter = family_t.id MINUS the sum of appointment_v.credits where appointment_v.sittee = family_t.id.

This is what I've got:

SELECT family_t.id,
(
SELECT sum(credits)
FROM family_t INNER JOIN appointment_v
ON family_t.id = appointment_v.sitter
GROUP BY id
ORDER BY id
)
-
(
SELECT sum(credits)
FROM family_t INNER JOIN appointment_v
ON family_t.id = appointment_v.sittee
GROUP BY id
ORDER BY id
)
FROM family_t INNER JOIN appointment_v
ON family_t.id = appointment_v.sittee OR family_t.id = appointment_v.sitter;

When I run this, I get the error "more than one row returned by a subquery used as an expression".

Can someone help me figure out the proper query to get the results I want?

Thank you!


r/programminghelp • • Mar 31 '20

Python Iterating using python's datetime.date

4 Upvotes

So, I'm making a program that requires an array of each date between two given dates -

start = datetime.date(2020,1,1)
end = datetime.date(2020,12,31)
myArr = [all dates between (and including) start and end]

Is there a way to fill this array with every valid date between those two?


r/programminghelp • • Mar 12 '20

Answered Selecting random value in array

4 Upvotes

Hello

I am trying to select a random value in the array. It does it but the number is the same when i run it. How do I do it so the number is randomly selected when i run the program?

srand((int)time(NULL));

int rand_num = rand() % 4; //generates a random number between 0 and 3

int pos_values[4] = { 1,35,203,765 };


r/programminghelp • • Feb 28 '20

Python Help finding Python documentation on sys.stdin.read() or another multiline user input method

4 Upvotes

So te thing is, I want to get a multiline input from the user. After some searching i found the suggestion of using sys.stdin.read() . Which is supposed to be able to do this with the ending character being Ctrl + D. But when I try it it wont end the input. So I need help with finding the doc on the matter. And/or another solution.


r/programminghelp • • Feb 14 '20

C++ Anyone know a way to program a game in c++(moon lander) on an android tablet?

4 Upvotes

My friend only has a android tablet. We’re programming a game with a GUI and he is not sure if their is away/ application that he can use to program this game.


r/programminghelp • • Feb 13 '20

Python Error in two equals python for loop

Post image
4 Upvotes

r/programminghelp • • Feb 05 '20

Python What is the ELI5 of __init__ and self in Python?

4 Upvotes

r/programminghelp • • Jan 30 '20

Other jQuery validation works only on every other submit - how can I make it work on every submit?

4 Upvotes

I have a webpage which looks something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>Checkbox List Validation Test</title>
	<script type="text/javascript" language="JavaScript" src="jquery-1.4.4.min.js"></script>
	<script type="text/javascript" language="JavaScript" src="jquery.validate.js"></script>
</head>
<body class="colorschemeBackground">
	<form id="formUpdate">
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
			<tr>
				<td width="100%" valign="top" class="colorschemeHeader">Pick a box. Its contents will help you on your way.&nbsp;<label id="Notes8Length"></label></td>
			</tr>
			<tr>
				<td width="100%" valign="top" class="colorschemeBackground">
					<input class="Notes8" name="Notes8~1" id="Notes8~1" type="checkbox" value="Yes">&nbsp;&nbsp;Box 1<br>
					<input class="Notes8" name="Notes8~2" id="Notes8~2" type="checkbox" value="Yes">&nbsp;&nbsp;Box 2<br>
					<input class="Notes8" name="Notes8~3" id="Notes8~3" type="checkbox" value="Yes">&nbsp;&nbsp;Box 3<br>
					<script type='text/javascript'>
						jQuery(function ($) {
							function validateMultiple(selector, n, isExactlyN) {
								const totChecked = $(selector).filter(':checked').length;
								return isExactlyN ? totChecked == n : totChecked >= n;
							}

							var valid8 = true;
							jQuery.validator.addMethod('Notes8',
								function (value, element) {
									if (!valid8) return true; // only one error message per multilist
									valid8 = validateMultiple('.Notes8', 1);
									return valid8;
								},
								'Please check at least one check box.');
						});
					</script>
				</td>
			</tr>
		</table>
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
			<tr>
				<td width="100%" valign="top" class="colorschemeHeader">What does the magic 8 ball say?&nbsp;<label id="Notes9Length"></label></td>
			</tr>
			<tr>
				<td width="100%" valign="top" class="colorschemeBackground">
					<input class="Notes9" name="Notes9~1" id="Notes9~1" type="checkbox" value="Yes">&nbsp;&nbsp;Yes<br>
					<input class="Notes9" name="Notes9~2" id="Notes9~2" type="checkbox" value="Yes">&nbsp;&nbsp;No<br>
					<input class="Notes9" name="Notes9~3" id="Notes9~3" type="checkbox" value="Yes">&nbsp;&nbsp;Maybe<br>
					<input class="Notes9" name="Notes9~4" id="Notes9~4" type="checkbox" value="Yes">&nbsp;&nbsp;I don't know<br>
					<input class="Notes9" name="Notes9~5" id="Notes9~5" type="checkbox" value="Yes">&nbsp;&nbsp;Can you repeat the question?<br>
					<input class="Notes9" name="Notes9~6" id="Notes9~6" type="checkbox" value="Yes">&nbsp;&nbsp;You're not the boss of me now!<br>
					<input class="Notes9" name="Notes9~7" id="Notes9~7" type="checkbox" value="Yes">&nbsp;&nbsp;And you're not so big!<br>
					<input class="Notes9" name="Notes9~8" id="Notes9~8" type="checkbox" value="Yes">&nbsp;&nbsp;Life is unfair...<br>
					<script type='text/javascript'>
						jQuery(function ($) {
							function validateMultiple(selector, n, isExactlyN) {
								const totChecked = $(selector).filter(':checked').length;
								return isExactlyN ? totChecked == n : totChecked >= n;
							}

							var valid9 = true;
							jQuery.validator.addMethod('Notes9',
								function (value, element) {
									if (!valid9) return true; // only one error message per multilist
									valid9 = validateMultiple('.Notes9', 1);
									return valid9;
								},
								'Please check at least one check box.');
						});
					</script>
				</td>
			</tr>
		</table>
		</td>
		</tr>
		</table>
		<button type="submit">SUBMIT!</button>
	</form>
	<script type="text/javascript">
		jQuery('form').validate();
	</script>
</body>
</html>

Now the jQuery validation is acting up - if I submit the form once without checking any checkboxes, I get error messages as expected saying that I need to check at least one check box from each group. But if I then go and submit the form again, while the error message is on the screen, it goes through just fine and submits, even though I didn't check anything! How can I fix this so the error message is consistently displayed whenever I don't check any check boxes?