Ask coding questions

Posts
Pinned
27
What should we code?
I've seen a couple of posts around here where people are asking what they should work on next. Let's use this space to brainstorm some cool projects.
95
posted by katyadee (613) 18 days ago
Pinned
62
Guide to Asking Coding Questions
# **Guide to Asking Coding Questions** ## **Why?** Good questions help your question be solved faster, and people will want to answer your question Bad questions waste time, you will often not get answers that you asked for, and people will often ignore your questions ## **Quick Questions Guide** ### Do This - Always ask your questions in English - Explain what you want the code to do - Explain what the code does - Include error messages - Share the repl with the line numbers - When you figure out the answer, update your post - Put the repl link, instead of pasting code ### Don't Do This - Don't post homework questions - Don't use caps in the title - Don't use words like 'HELP' or 'PLEASE' in the title - Don't post questions that already have an answer (Search Box) - Don't post feedback or bugs on Talk, use [repl.it/feedback](https://repl.it/feedback) for feedback, or [repl.it/bugs](https://repl.it/bugs) for bugs ## **Steps For Better Questions** 1. Understand the code - Read your code and figure out what each line does - If a concept is unfamiliar, Google it - You can also use a debugger to help you 2. Describe the problem - Explain what you want the code to do - Explain what the code does (error messages) 3. Provide the code - Share a repl that has your code - Share the line number(s) of your code issue - Make sure that the code you shared has the issue 4. Format code consistently - Make sure your code is easy to read 5. Check for typos - Make sure the code does not have any typos that would cause the problem 6. Explain what you did to troubleshoot the problem - Make a list of what you think the problem is and try to fix your problem by going through the list 7. Make a guess on what you think the problem might be - Use the list from the previous step 8. Proofread the question - Make sure you provided everything - Clear all confusions that you think there might be 9. Update people on the question - If you figured out the answer, edit the post to tell people - When you get an answer, fully understand it - Be nice to people who answer your question - Remember that the people wanted to answer your question, but didn't have to 10. Things to NOT do - Don't post homework questions - Only post questions in English - Do not use caps in the title - Do not use "HELP" or "PLEASE" in the title - Don't post questions that have already been answered (Use search box) - Don't post feedback or bugs on Talk, use [repl.it/feedback](https://repl.it/feedback) for feedback, or [repl.it/bugs](https://repl.it/bugs) for bugs ## **Example:** ### **Question** We have some Python code with an error: [repl](https://repl.it/@Mosrod/Question-Tutorial) ```python rannumexe = int(input()) if rannumexe = 1: print('hi' + rannumexe) ``` ### Step 1 We show what each line does using comments. ```python rannumexe = int(input()) # Asks the user to input a rannumexe if rannumexe = 1: # If the rannumexe equals 1 print('hi' + rannumexe) # Print hi and the rannumexe ``` ### Step 2 We want the code to input a number, and if the number is one, print "hi" and the number. Our problem is that we have an invalid syntax error on line 2 in the main.py file. ``` File "main.py", line 2 if rannumexe = 1: ^ SyntaxError: invalid syntax ``` ### Step 3 Our repl with the issue is located [here](https://repl.it/@Mosrod/Question-Tutorial). We have an issue on line 2 ### Step 4 We can change "rannumexe" to "number" to clear confusion ```python number = int(input()) # Asks the user to input a number if number = 1: # If the number equals 1 print('hi' + number) # Print hi and the number ``` ### Step 5 We don't have any typos ### Step 6 Our problem could be that we improperly used the if statement ### Step 7 The problem could be about using the if statement incorrectly ### Step 8 Our final question: Title: Invalid syntax error about equal signs Content: I have an invalid syntax error on line 2 in the main.py file of this [repl](https://repl.it/@Mosrod/Question-Tutorial). The program should take a number as an input, check if the number is equal to one, and if so, print "hi" and the number. The error point to the equal signs and I think this issue is with the incorrect syntax of the if statement. Help is appreciated :). ```python number = int(input()) # Asks the user to input a number if number = 1: # If the number equals 1 print('hi' + number) # Print hi and the number ``` ``` File "main.py", line 2 if rannumexe = 1: ^ SyntaxError: invalid syntax ``` Steps based on Gordon Zhu's [post](https://medium.com/@gordon_zhu/how-to-be-great-at-asking-questions-e37be04d0603). If you have any suggestions or feedback, post it in the comments below.
31
posted by Mosrod (242) 9 months ago
1
Which JavaScript editor and code-completion utlitily is provided by repl.it?
I am impressed with the JavaScript code editor provided in each JS repl. Which one is it?
1
posted by jgcoding (0) 2 hours ago
1
Problem with pygame
Hi! I've got this error when i run an working pygame-script: 'bash -c polygott-x11-vnc q && DISPLAY=:0 run-project nohup: redirecting stderr to stdout' The code is perfectly working on local python-installation...need help! THX! CODE ' import pygame pygame.init() screenx = 400 screeny = 300 window = pygame.display.set_mode((screenx,screeny)) counter = 0 run = True class Viereck: x = 0 y = 0 breite = 0 hoehe = 0 farbe = (0,0,0) speed = 10 def __init__(self, x, y, breite, hoehe, farbe): self.x = x self.y = y self.breite = breite self.hoehe = hoehe self.farbe = farbe def zeichneMich(self, fenster): pygame.draw.rect(fenster, self.farbe, pygame.Rect(self.x,self.y,self.breite,self.hoehe)) def bewege(self, x, y): self.x += x self.y += y viereck1 = Viereck(250,10,40,40,(255,255,255)) viereck2 = Viereck(10,150,20,20,(255,0,255)) def zeichne(fenster): fenster.fill((0,0,0)) viereck1.zeichneMich(fenster) viereck2.zeichneMich(fenster) pygame.display.update() while run: pygame.time.delay(28) zeichne(window) counter +=1 # VIERECKE BEWEGEN #viereck1.bewege(counter*1, 0) #viereck2.bewege(counter*2, 0) #if counter == 100: # run = False for event in pygame.event.get(): if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: viereck1.bewege(viereck1.speed*-1, 0) pygame.quit() '
1
posted by holgertrampe (0) 2 hours ago
3
Daily Question #1
I have started a daily question thread, mainly because why not? Some of these questions will be about coding, some will be about any other topic. The first daily question, today will be: Which games engine would you think of programming with and why? Mine is Ren'Py because it is versatile and everything you need is there to create a really cool Visual novel. It was also made to use two of my favourite games, Doki Doki Literature Club and Danganronpa
2
posted by ReshiramWolfu (20) 4 hours ago
Python
Python
1
Saving files
How do I save a file in repl.it? I can't find it anywhere in the interface.
2
posted by aligoucem (0) 7 hours ago
1
Change Variables Integrers.
So, i am trying to change a variable from 0 to 10 (+10) but it gives me error. How can i print integers?? ![image](https://storage.googleapis.com/replit/images/1560842666952_7c9b5a196abbfd47b6963bb758b6211d.pn)
2
posted by IzanLarumbe (23) 8 hours ago
1
HTML Comment Doubt 2
Er, so it is working on a repl. But in my exams, I will be having to do HTML Codes in Notepad, because of our REALLY bad internet connection. So I usually practice it in Notepad, and just to get the hang of it, I also practice on Repl.it. But when I try this commenting in Notepad it doesn't seem to work, and in the browser, it keeps on getting displayed here: In the tab address. Any clues on what I'm doing wrong? And my first HTML Comment Doubt is here https://repl.it/talk/ask/HTML-Comment-doubt/15807/41320?from=notifications
0
posted by Lanna (32) 10 hours ago
1
knapsack problem
¿how do you solve a knapsack problem that has 3 variables?
0
posted by Prankishtik2 (0) 11 hours ago
Lua
Lua
1
How to set decimals on the moon?
I am doing a circle area code and i need to delimit the number of decimal places, but i do not know how it works on the moon
0
posted by TryAgain (0) 12 hours ago
answered
1
Functions not running.
Hi, i am making a game called SpainLovesPolitics. And i am making a function, but when i do function() it does not run automatically, it has to be runned by the user, how can i make it so it runs automatically? Also here's the code: ![image](https://storage.googleapis.com/replit/images/1560802440286_4f5390ded15c1c22a2ad53af16722e81.pn)
3
posted by IzanLarumbe (23) 19 hours ago
1
Django, need to use pip installed module in installed apps
When I start my Django project it pip installs the module fine but when I reference it in my installed apps in settings.py, it states that no such module exists. How am I supposed to reference the module so that it woks, thanks in advance for your guy's help :)
2
posted by newCrisco (0) 21 hours ago
1
HTML Comment doubt
![image](https://storage.googleapis.com/replit/images/1560794335776_99dfaefc9502121e9344fe273339173d.pn) So am I doing anything wrong in this commenting? 'Cause it ain't working, the comment is not supposed to be displayed but it is, why?
5
posted by Lanna (32) 21 hours ago
1
Why REpl.it works best in Chrome?
Why Repl.it works best in Chrome? Sometimes it does not work using other browser or it takes longer to launch it.
1
posted by Chonajava2019 (0) 22 hours ago
answered
Python
Python
0
files
This is pretty basic, but how do you run code in files outside of "main.py"? Maybe I am not seeing something. Thx
2
posted by ryanrwatkins (0) 22 hours ago
1
SyntaxError
// Spirograph simulator for MPCNC used as plotter // Ed Nisley KE4ZNU - 2017-12-23 // Spirograph equations: // https://en.wikipedia.org/wiki/Spirograph // Loosely based on GCMC cycloids.gcmc demo: // https://gitlab.com/gcmc/gcmc/tree/master/example/cycloids.gcmc // Required command line parameters: // -D Pen=n pen selection for tool change and legend position // -D PaperSize=[x,y] overall sheet size: [17in,11in] // -D PRNG_Seed=i non-zero random number seed include("tracepath.inc.gcmc"); include("engrave.inc.gcmc"); //----- // Greatest Common Divisor // https://en.wikipedia.org/wiki/Greatest_common_divisor#Using_Euclid's_algorithm // Inputs = integers without units function gcd(a, b) { local d=0; if (!isnone(a) || isfloat(a) || !isnone(b) || isfloat(b)) { warning("Values must be dimensionless integers"); } while (!((a | b) & 1)) { // remove and tally common factors of two a >>= 1; b >>= 1; d++; } while (a != b) { if (!(a & 1)) {a >>= 1;} // discard non-common factor of 2 else if (!(b & 1)) {b >>= 1;} // ... likewise else if (a > b) {a = (a - b) >> 1;} // gcd(a,b) also divides a-b else {b = (b - a) >> 1;} // ... likewise } local GCD = a*(1 << d); // form gcd // message("GCD: ",GCD); return GCD; } //----- // Max and min functions function max(x,y) { return (x > y) ? x : y; } function min(x,y) { return (x < y) ? x : y; } //----- // Pseudo-random number generator // Based on xorshift: // https://en.wikipedia.org/wiki/Xorshift // www.jstatsoft.org/v08/i14/paper // Requires initial state from calling script // -D "PRNG_Seed=$(date +%N)" function XORshift() { local x = PRNG_State; x ^= x << 13; x ^= x >> 17; x ^= x << 5; PRNG_State = x; return x; } //----- // Spirograph tooth counts mooched from: // http://nathanfriend.io/inspirograph/ // Stators has both inside and outside counts, because we're not fussy Stators = [96, 105, 144, 150]; Rotors = [24, 30, 32, 36, 40, 45, 48, 50, 52, 56, 60, 63, 64, 72, 75, 80, 84]; //----- // Start drawing things // Set these variables from command line comment("PRNG seed: ",PRNG_Seed); PRNG_State = PRNG_Seed; // Define some useful constants AngleStep = 2.0deg; Margins = [0.5in,0.5in] * 2; comment("Paper size: ",PaperSize); PlotSize = PaperSize - Margins; comment("PlotSize: ",PlotSize); //----- // Set up gearing s = (XORshift() & 0xffff) % count(Stators); StatorTeeth = Stators[s]; comment("Stator ",s,": ",StatorTeeth); r = (XORshift() & 0xffff) % count(Rotors); RotorTeeth = Rotors[r]; comment("Rotor ",r,": ",RotorTeeth); GCD = gcd(StatorTeeth,RotorTeeth); // reduce teeth to ratio of least integers comment("GCD: ",GCD); StatorN = StatorTeeth / GCD; RotorM = RotorTeeth / GCD; L = to_float((XORshift() & 0x3ff) - 512) / 100.0; // normalized pen offset in rotor comment("Offset: ", L); sgn = sign((XORshift() & 0xff) - 128); K = sgn*to_float(RotorM) / to_float(StatorN); // normalized rotor dia comment("Dia ratio: ",K); Lobes = StatorN; // having removed all common factors Turns = RotorM; comment("Lobes: ", Lobes); comment("Turns: ", Turns); //----- // Crank out a list of points in normalized coordinates Path = {}; Xmax = 0.0; Xmin = 0.0; Ymax = 0.0; Ymin = 0.0; for (a=0.0deg ; a <= Turns*360deg ; a += AngleStep) { x = (1 - K)*cos(a) + L*K*cos(a*(1 - K)/K); if (x > Xmax) {Xmax = x;} else if (x < Xmin) {Xmin = x;} y = (1 - K)*sin(a) - L*K*sin(a*(1 - K)/K); if (y > Ymax) {Ymax = y;} else if (y < Ymin) {Ymin = y;} Path += {[x,y]}; } //message("Max X: ", Xmax, " Y: ", Ymax); //message("Min X: ", Xmin, " Y: ", Ymin); // min will always be negative Xmax = max(Xmax,-Xmin); // odd lobes can cause min != max Ymax = max(Ymax,-Ymin); // ... need really truly absolute maximum //----- // Scale points to actual plot size PlotScale = [PlotSize.x / (2*Xmax), PlotSize.y / (2*Ymax)]; comment("Plot scale: ", PlotScale); Points = scale(Path,PlotScale); // fill page, origin at center //----- // Set up pen if (Pen > 0) { comment("Tool change: ",Pen); toolchange(Pen); } //----- // Plot the curve feedrate(3000.0mm); safe_z = 1.0mm; plot_z = -1.0mm; tracepath(Points, plot_z); //----- // Put legend in proper location feedrate(500mm); TextSize = [3.0mm,3.0mm]; TextLeading = 1.5; // line spacing as multiple of nominal text height MaxPen = 4; line1 = typeset("Seed: " + PRNG_Seed + " Stator: " + StatorTeeth + " Rotor: " + RotorTeeth,FONT_HSANS_1); line2 = typeset("Offset: " + L + " GCD: " + GCD + " Lobes: " + Lobes + " Turns: " + Turns,FONT_HSANS_1); maxlength = TextSize.x * max(line1[-1].x,line2[-1].x); textpath = line1 + (line2 - [-, TextLeading, -]); // undef - n -> undef to preserve coordinates if (Pen == 1 || Pen > MaxPen ) { // catch and fix obviously bogus pen selections textorg = [PlotSize.x/2 - maxlength,-(PlotSize.y/2 - TextLeading*TextSize.y)]; } else if (Pen == 2) { textorg = [-PlotSize.x/2,-(PlotSize.y/2 - TextLeading*TextSize.y)]; } else if (Pen == 3) { textorg = [PlotSize.x/2 - maxlength, PlotSize.y/2 - TextSize.y]; } else if (Pen == 4) { textorg = [-PlotSize.x/2, PlotSize.y/2 - TextSize.y]; } else { Pen = 0; // squelch truly bogus pens textorg = [0mm,0mm]; // just to define it } if (Pen) { // Pen = 0 suppresses legend placepath = scale(textpath,TextSize) + textorg; comment("Legend begins"); engrave(placepath,safe_z,plot_z); } if (Pen == 1) { // add attribution along right margin attrpath = typeset("Ed Nisley - KE4ZNU - softsolder.com",FONT_HSANS_1); attrpath = rotate_xy(attrpath,90deg); attrorg = [PlotSize.x/2,5*TextLeading*TextSize.y - PlotSize.y/2]; placepath = scale(attrpath,TextSize) + attrorg; comment("Attribution begins"); engrave(placepath,safe_z,plot_z); } goto([-,-,25.0mm]);
0
posted by ZacharieAertsse (0) 22 hours ago
answered
3
CSS Question
Hi, does anyone here know how to merge external, internal and inline style sheets in one HTML webpage? If we merge the files, then what type of stylesheet is supposed to be of highest priority?
6
posted by Lanna (32) 24 hours ago
answered
Java
Java
1
oi its broken
cheers fix it please cos im trash coder need help 5$ paypal to whoever helps cheers x x x x x x x x x x x x
2
posted by DanielBrammer33 (0) 1 day ago
answered
2
what is lolcode ?
I was bored and I looked all every language of code that you can write on repl.it, after that I found a language called **Lol code** My question is very simple : **What in the world is "lol code" ?**
2
posted by lsambrook (199) 1 day ago
Python
Python
2
set breakpoint pyton 3.6
How do i set a breakpoint in the debugger? (Python 3.6)
2
posted by r1200gs (1) 2 days ago
Python (with Turtle)
Python (with Turtle)
1
test
i have a test at school and i do'nt no what to do
1
posted by FololesiaOtutah (0) 2 days ago
1
Can i have my repl back, Timchen?
You deleted my AZURE repl, and you have yet to bring it back for me to copy the contents... i worked hard on it ya know...
3
posted by AzureScripts (124) 2 days ago
Python
Python
1
vicky
140406 sirhind fatehgarhsahib an what is your comment about my coding of python please tell me as very freely mode
2
posted by VickySingh (0) 2 days ago
Pygame
Pygame
1
A PyGame Noob's questions
I have no idea how to work PyGame. I know how to work Python, but not PyGame. Can someone plz give basic commands to play around with?
1
posted by Infinity_Coder (0) 3 days ago
1
Code Completion not working for C++ Repl.it
https://repl.it/@anshuldaga/Project1 Hi my code completion is not working for any other file other than my main.cpp. Any idea why this is happening? Thanks! I'm also getting an error in my JS Console. Don't know if it's related. ![image](https://storage.googleapis.com/replit/images/1560619647399_d87a74f5a432bcc2bb46d1cf25be44ea.pn)
2
posted by anshuldaga (0) 3 days ago
1
why can I not import JSON object in java 1.8
I am trying to import a library that can help me access JSONObjects, but nothing seems to work. Does anybody know which library needs to be imported (there is no org.json)
2
posted by shivangi007 (0) 3 days ago
answered
2
creating and reading JSON files
wondering how to set up a JSON database and how to read it in JS
1
posted by Nanowrimoijk (22) 3 days ago
1
programme pour identifier un nombre premier
bonjour j'ai besoin de connaitre le programme pour identifier un nombre premier voici ce que j'ai fait : def goldbach(n): p=3 q=n-p for i in range(3,n): if q%i == 0 and i!=q : q=n+(p+2) else: return p, q
2
posted by Mohamadaliatwi (0) 3 days ago
1
My (Dutch) questionnaire is stuck in a loop
I'm programing a questionnaire for a team with 3 statements about trust. Ppl have to answer by saying: 1 if the statement never happens 2 if it sometimes happens, and 3 if it happens often. If the sum of their answers on those 3 statements <=5 then an open question about trust has to be printed If not, then the questionnaire goes on with 3 new statements about conflict in their team. My questionnaire is stuck in a loop. It asks statement 1 about trust Then you can answer And after answering 1, 2, or 3, you click enter, and that same question prints. It doesn't go to statement 2. Can someone help me with that? https://repl.it/@erikasomers/Vragenlijst The code is in the 'asked on repl.it folder
3
posted by erikasomers (0) 3 days ago
C
C
1
how to save my c programs on repl.it
I have typed a c program how to save that program on repl.it
2
posted by shaikshafiya (0) 3 days ago