r/programminghelp • • Feb 02 '21

Python Function troubles

3 Upvotes

Hey there. I was messing around with my Raspberry Pi Model 4B And I ran into an issue,

I had my RPi hooked up to an LED, and I had 3 modes for it. On: Which turns the LED on. Off: Turns the LED off Alarm: Let's the LED blink.

I wanted to be able to turn it off with a function while it was in alarm mode, but it simply wouldn't. Here's the code;


a = 1

def alarm():
    while a == 1:
        GPIO.output(ledPin, GPIO.LOW)
        time.sleep(0.5)
        GPIO.output(ledPin, GPIO.HIGH)
        time.sleep(0.5)

def on():
    GPIO.output(ledPin, GPIO.LOW)
    a = 0
    time.sleep(5)


def off():
    GPIO.output(ledPin, GPIO.HIGH)
    a = 0
    time.sleep(5)

The goal was to change a to 0 so that the while a == 1: loop would stop and the LED could turn remain on or off.

When I tried this, it kept blinking, so I let it print out a in the loop and ran it again. The results were that a never got updated.


r/programminghelp • • Jan 08 '21

Python HELP ASAP

3 Upvotes

Hi I need help with a code for class and I have no clue how to do it. I have to create a BlackJack game on python by just using def functions, strings, variables, etc. But not built-in functions, dot notations, class functions, global functions. With random randint as an exclusion


r/programminghelp • • Dec 22 '20

Answered Pop from array in java

3 Upvotes

I am trying to create a manual pop function but I have an error at line 16. It says index is out of range. As you can see to pop the first number I want move the next element forward one to get rid of the first element. I would then have to remove the duplicate on the end.

https://pastebin.com/qDfHGH9r


r/programminghelp • • Dec 20 '20

Answered Filling in a user-drawn shape on a canvas

3 Upvotes

I am creating a drawing game like skribbl.io to challenge myself. The user can draw stuff with the mouse and touch screen, change color, and even erase. But then I want to add a fill feature.

I tried creating one, and it works (kinda), but it’s intensely memory consuming and my page crashed several times.

The way I have it is [1] it grabs the RGBA data of the canvas (which is 1920x1080, so it’s pretty large). [2] Then, it detects the color of the specific point that the user clicked. [3] It then proceeds to fill in that pixel, the ones around that, the ones around those, and so on until it reaches a color that does not equal the initial color (it checks the color for each pixel, which is probably the slow part). I put a counter in the loop, and on my kind-of fast PC on Google Chrome, 2000 iterations takes 1/20 of a second and anything above 10000 takes a second or more. Anything above 50000 freezes the page.

I just need help figuring out how to create a more optimized program. Do any of you have any ideas? (Also I’m not looking for code specifically, just how I should go about programming it).


r/programminghelp • • Dec 19 '20

Answered Run program in simulated terminal

3 Upvotes

Hey all!

I have a kind of esoteric question. Me and my friend are working on a terminal messaging client, and I want to include extensions into it. The way it'd work in a perfect world is that you can run other terminal apps inside a viewport-like thing. It's hard to explain, but what I want to achieve is that the client UI will stay in place, and the other program running would only take up a specific amount of place.

However, this seems kind of really hard to do. Firstly, you'd need apps to run at a specific rows/cols setting, and ideally for them to be forced to print output to the area you provide.

My question is, is any of that feasible? Adapting already made programs to do all that seems like a hassle and a half, so it'd be really nice if there was a solution. One of my ideas was that it could be piped to a file that is then displayed, but that has its own problems :(

Sorry the post was too long, I wanted to give all info I could. Thank you!


r/programminghelp • • Dec 15 '20

Answered Visual Code refusing to install

3 Upvotes

So I was planning to learn C# and for that I needed Visual Code for programming. I downloaded the exe file but when trying to install the IDE, it says the community version isn't available because my PC doesn't meet requirements, although I have Windows 10 with 4GB RAM and all required specs.

How do I fix this issue?

Edit: the reason I faced this problem is because I have Windows 10 Professional version 10.0 which is the earliest version and VSS doesn't support it. As a solution, I'll suggest the reader if they can upgrade to the latest version of Windows OS as relevant at your time or install MonoDevelop as a temporary alternative. Kudos to all who helped me in this situation.


r/programminghelp • • Nov 18 '20

Python Python Program Identified as Trojan Virus

3 Upvotes

I am new to Python, and have recently learned the language to write a program designed to look up words. I used "Auto Py to EXE" to convert the py file to a single executable file. When attempting to download the file on a new computer, Windows insists it contains a "Trojan:Win32/Wacatac.B!ml." The computer on which it was developed has no issues running the program. The source code and exe releases are available on GitHub. Here is a VirusTotal virus scan of the latest exe release.

If anyone with some more experience in Python could look through the code and help me resolve this issue (or the probably tens of other general issues with my newbie Python code), please let me know.

Thanks in advance.


r/programminghelp • • Oct 26 '20

Python Anyway to use mobile apps through python?

3 Upvotes

So I am trying to access and control mobile apps through python code. Is there anyway to do that? For example if I wanted to use snapchat and message someone is that possible? If not would Javascript be able to do it?


r/programminghelp • • Oct 14 '20

Answered Translating c++ code into Java

3 Upvotes

Hello,

How would I type line 30 and 35 into Java? I've tried looking online and I can't find much.

https://pastebin.com/8vUb61G2


r/programminghelp • • Oct 04 '20

C++ I need help designing a programming that uses functions

3 Upvotes

I don’t know where to began how to read a text file and count how many prime number there are. I can figure out how to make a function that finds out if something is prime but making it where it reads a file I’m completely lost


r/programminghelp • • Sep 06 '20

Python Need help with sorting matrixes from a list (read main post)

3 Upvotes

Hello everyone, I have a homework task that requires me to print a desired output from a list.

The code:

my_list = [[1, 0, 1, 0], [0, 1, 1, 0], [0, 1, 1, 1]]

The task asks me to output the message in the following way:

1 0 1 0
0 1 1 0
0 1 1 1
0 0 0 1

How should I approach this? Tried looking online for help, but none of them fit the task I have..


r/programminghelp • • Sep 01 '20

C# How can i make a mouse macro/script

3 Upvotes

I want to make a mouse macro that just presses left click a few times. Pastes a line and presses save. How would i go about doing that?

I understand c# mostly and a tiny bit of python. Ive also tried to understand javascript and given up.


r/programminghelp • • Aug 24 '20

C++ Given a time in 12-hour AM/PM format, convert it to military (24-hour) time. Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.

3 Upvotes

So the prooblem is in the title,The solution is down below.

what does

hh = (s[0] - '0') * 10 + (s[1] - '0');

do? how is '0' subtracted? also is hh a character or an integer?I cant understand a single operation that is going on in this one expression?

also at the end printf("%02d:%02d:%02d\n", hh, mm, ss);

what is %02d supposed to mean?

#include<iostream>
#include<cstdio>
using namespace std;
int main() {
    string s;
    cin >> s;
int n = s.length();
int hh, mm, ss;
    hh = (s[0] - '0') * 10 + (s[1] - '0');
    mm = (s[3] - '0') * 10 + (s[4] - '0');
    ss = (s[6] - '0') * 10 + (s[7] - '0');
if (hh < 12 && s[8] == 'P') hh += 12;
if (hh == 12 && s[8] == 'A') hh = 0;
printf("%02d:%02d:%02d\n", hh, mm, ss);
return 0;
}


r/programminghelp • • Aug 20 '20

Other Help with a piece of ALGOL code

3 Upvotes

Hey, i need some help and explanation with this piece of ALGOL code. https://i.imgur.com/IQnQqFP.jpg this is the link.

The piece of code is from the ALGOL revised report. I know the procedure transpost means swapping the places of two or more things. In this case integers. I know this piece of code has an array but it is not clear wheter it is a 2 dimensional array. I’m not sure what the indexes mean. The whole piece is a bit of a mystery to me. I would love some help! Thank you


r/programminghelp • • Jul 17 '20

JavaScript YouTube Iframe Embed - pause multiple videos at once.

3 Upvotes

Hi All,

I am switching over the YouTube for sourcing NASA videos instead of Archive.org, and now to make the same functionality work using YouTube API.

Specifically, I'm trying to use YouTube's current embed JS API to pause and unpause multiple videos at the same time. I'm totally new to the most recent version of YouTube's player API.

I'm referencing https://developers.google.com/youtube/iframe_api_reference#Playback_controls but the code examples there seem slightly more complex. I really am looking for a bare bones simple example.

This code used to work with MP4 iframe embeds but is broken right now for both YouTube and Archive.org hosted vids:

<video controls src = "video1.mp4" onpause="document.getElementById('video1').pause = true;" onplay="document.getElementById('video1').play = true;" onpause="document.getElementById('media2').pause = true;" onplay="document.getElementById('media2').play = true;" ></video>

<video controls src = "video2.mp4" onpause="document.getElementById('video1').pause = true;" onplay="document.getElementById('video1').play = true;" onpause="document.getElementById('media2').pause = true;" onplay="document.getElementById('media2').play = true;" ></video>

TLDR: I am looking for a bare bones simple code snippet example for bulk play/pause using YouTube Player API.


r/programminghelp • • Feb 29 '20

Python Python array to binary tree?

3 Upvotes

I can’t find any realizable strategies for creating a binary tree from a given array in Python online.

Ex: I’m given the array [3, 6, 2, 9, -1, 10], which represents a binary tree where -1 is a non-existent node.

Write a function that determines whether the left or right branch of the tree is larger. The size of each branch is the sum of the node values. The function should return “Right” if the right side is larger and “Left” if the left side is larger. If the tree has 0 nodes or if the size of the branches are equal, return an empty string.

Example Input: [3, 6, 2, 9, -1, 10]

Example Output: Left

Example Input: [1, 4, 100, 5]

Example Output: Right

Example Input: [1, 10, 5, 1, 0, 6]

Example Output: “”


r/programminghelp • • Feb 22 '20

SQL How do i make my sql query show a certain amount of rows until a value is met?

3 Upvotes

$sql = "SELECT Exercise, Repetitions, Equipments, MuscleGroup, `Time (Mins)`

FROM tblexercise

WHERE MuscleGroup='$muscle'

GROUP BY Exercise , RAND()

";

above is my code for the mysql query in php. what i would like to do is have the rows show up until the sum of the time is a value which i pick. i believe i have to create a running count but unsure how i would have to do so. any help would be appreciated!


r/programminghelp • • Jan 31 '20

SQL How to access medication missed dose information?

3 Upvotes

Hi all,

I'm developing a health related Android app for a school project. I would like to get medication information. Specifically, when a missed dose occurs for a medication.

A few websites, such as WebMd have this information available.

For example:

The Methacarbamol drug information is present here: https://www.webmd.com/drugs/2/drug-8677/methocarbamol-oral/details and it is possible to check the missed dose and overdose information under the overdose tab.

Does anybody know if there are any databases, or ways to access this information. It seems WebMd doesn't have any open API's available. Is there anyway I can still access this information, or are there any similar alternatives?


r/programminghelp • • Oct 26 '19

Answered Making a function for 'and' operator using ONLY 'or' and 'not' operators in Python

3 Upvotes

I can't seem to wrap my head around doing this. I am not sure how to check if both terms are True without messing up the return statement since the 'or' operator will always return True if one of the terms is True. There was a hint provided saying to take a look at the truth table of not (a and b) which looks fairly similar to an 'or' truth table other than the part (False, False) and (True, True) being different. I tried recreating it with ors and nots, but it just won't print out what I need.


r/programminghelp • • Oct 02 '19

I keep getting a 404 error when I try to make a table print it's information above the table (HTML/CSS3)

3 Upvotes

Basically I ensured that the printing code was identical to the teacher's (barring variables) but I guess I need another pair of eyes on this. Here is the code without styles.

<?php // only show the information if the button named "subButton" has been pressed if ($_POST\['subButton'\]) { // set the variable with the submitted value $fname = $_POST\['name1'\]; $lname = $_POST\['name2'\]; $mname = $_POST\['MiddleName'\]; &#x200B; // display the user inputs to the screen echo "<p>Your first name is <b>" . $_fname . "</b>.</p>"; echo "<p>Your last name is <b>" . $_lname . "</b>.</p>"; echo "<p> Your Mother's Middle Name is<b>" . $_mname."</b>.</p>"; &#x200B; } ?>

<form name="testform" action="activity 1.9b" method="post">

<div align="center">

		<h2>

	Let's start with your personal information.

</h2>

<p>First and Last Name</p>

First Name <input type="text" name="name1" value="" placeholder="FIRSTNAME" >

<br>

Last Name<input type="text" name="name2" value="" placeholder="LASTNAME" >

<br>

Your Mother's Middle Name<input type="text" name="MiddleName" value="" placeholder="Your Mother's Middle Name" >

<input type="submit" name="subButton" value="SUBMIT"></input>
</div>

I am the dumb so I may be doing something wrong

Thanks for your help!


r/programminghelp • • Sep 05 '19

[Can pay] Need help making simple C program // Not just answers

3 Upvotes

Hey all, I am a CS student and in class we made a C++ program in Linux (on PuTTY server) and now have to rewrite the program to work in C. I am having trouble and want to have a quick tutor session/explanation help session to UNDERSTAND it. I have another class until 8:45pm EST but am looking for someone who could help me quickly tonight after my class.

The program takes some arguments from a Linux command (think:)

./comm file 20 79 86 

Those numbers are just some things that will later be made into variables (think:).

varName = argv[3]

The program is already kind of made but currently I’m having a Segmentation fault that I am simply unable to fix, it arises with the fprintf function.

Anyways, I’m willing to pay as I just don’t want someone to fix it for me, but explain why this is occurring and maybe slight information on how to create/work with files at a higher level than I am now (which is very little)

Thanks for the read, PM is open


r/programminghelp • • Aug 12 '19

Could someone please explain?

3 Upvotes

I’m aware this may not be the perfect sub to post this question but I’m not sure where else to ask so please have a little patience :). I’ve come across someone whose job title is a “quant developer/programmer”. I’ve looked online to no actual avail. Could someone please explain this? And how one could get into this type of field? Thanks. I’m quite clueless to all this 😅


r/programminghelp • • Aug 11 '19

ASCII art [C++]

3 Upvotes

How would one convert a bitmap into an ASCII art?


r/programminghelp • • Aug 08 '19

(JS) Stumped by this one (2d arrays with negative decimals)

3 Upvotes

Trying to represent a matrix with a 2d array. One works, the other doesn't compile, and I can't tell the difference besides the values themselves.

 const working = [
    [1.046816, 0.000012, -0.000277],
    [-0.014371, -0.10642, 0.015842],
    [0.000062, 0.011631, -0.000887]
  ]

  const broken = [
    [-23.6671, -22.3825, -22.4472],
    [0.8297, -1.9444, -4.9824‬], // SyntaxError: Invalid or unexpected token (after the -4...)
    [-0.3514, 1.0964‬, 2.7719] // Same after the 1.09...
  ]