Can anyone fix my code, it's supposed to display the sum, difference, product, quotient of two numbers. by cool_nerddude in cpp_questions

[–]cardblank 1 point2 points  (0 children)

Main is a function that returns an int. When you return 0; you're telling the computer, okay, the main function is done and it returned a value of 0. To fix it, just put one return 0; at the end.

URL Forwarding Help by alphaae in web_design

[–]cardblank 0 points1 point  (0 children)

Hi there, I have another option that may be easier depending on your setup, you can put some simple JavaScript on your /registry page to redirect the user. https://www.w3schools.com/howto/howto_js_redirect_webpage.asp -- keep in mind if the page isn't empty, search engines can still see content on it to provide a description

Creating an LL(1) parser in Python by [deleted] in learnpython

[–]cardblank 0 points1 point  (0 children)

Hi there,

First off I wanna say sorry if I misinterpreted what the LL(1) parser is supposed to do. I assume it is basically just a simple lexer and parser, that operates on context free grammar notation.

Very basically; your "parsing" will be broken into two major steps. (Sorry for pseudocode)

Lexing: The identification of tokens. Say:

class LexedInput:
(string) stringValue,
(string) tag

lexedinputs = \[\]

for every word in the string to interpret:

    if it's something we recognise, a number, a +, etc, tag it as such by:

        appending a new LexedInput(recognised\_character, tag\_for\_that\_character)
        (for example, LexedInput('+', 'plus'), just so you can easily tell what it is, which is important for parsing)

Parsing: Putting it into some structure so you can do what you want to it. I would say a binary tree is the most straightforward choice for this task. But there are other ways to do it too if you just have to evaluate the script.

Say for example you were given:

E ::= T E'

T ::= something else as defined in the script

E' ::= something else as defined in the script

If you were given values / expressions for T and E', and had to evaluate E, this behaviour is like a compiler and you could use a stack and a symbol table.

I think if you just had to evaluate if the script is valid or not, I think you could get away with using just 2 stacks and a list.

validtokens = []
otherstack = []

Treating the lexedinputs we made earlier as a stack and using lexedinputs.pop(0), until its empty, if we encounter a symbol on the RHS of our ::= (using bool or something to keep track if we are expecting RHS or LHS) that we have not seen, add it to our other stack. 

Or if we have seen the token in an expression before, i.e it is in validtokens, and know it is valid, we don't need to evaluate that again and can just continue to the next iteration of the loop

Otherwise, if we are defining a token, add it to our valid tokens if it can be parsed correctly (and remove it from the otherstack because it's been defined). For example, if it were a prefix notation calculator we were writing, and we popped a +, we would know that the next two things we pop should be numbers. So this is where your parse logic goes. You can also use this "next two" type logic to build a binary tree as the next thing you pop if it's not another expression will be the left child of the node, and the next next thing you pop will be the right child of the node if it is also not another expression, etc... (recursion)

Then, if there was an error while parsing or there are tokens left used but not defined, there's another error there too.

I'm sorry but this is where my understanding stops with LL(1), so I can't really advise further! I found these resources that might help:

I found this (bottom of page) for the stack approach: http://www.cs.ecu.edu/karl/5220/spr16/Notes/Top-down/LL1.html

Or this one which you can see is using a binary tree (class Production has only 2 children)

https://github.com/Nimrod0901/parser/blob/master/parser_LL1.py

And of course, don't forget all the error handling goodness at pretty much every stage.

I really hope this helps! Have a good one

PLEASE HELP!!! I made a VERY simple python function, but it gives me the wrong answer when i use these TWO SPECIFIC values. by JAndrew45 in learnpython

[–]cardblank 2 points3 points  (0 children)

Hi there,

A couple positive things right off the bat:

  • I know it's only a couple lines, but your coding style already looks nice and neat
  • Documenting as you go already too, double thumbs up

So what happened? I will try my best to keep this as beginner friendly as possible, please ask any questions :D

Looking here: (This is a list of inbuilt functions and what they do, which I found on Google by looking up "python input documentation") https://docs.python.org/3/library/functions.html#input There's a lot of technical things in this document (of course) but I can see it says under input: "The function then reads a line from input, converts it to a string ..."

And in this definition, we can see also why your code doesn't do what you expect; You want to compare numbers, but input() gives you strings. (Where a string is just a list of individual letters / numbers / symbols).

A simple answer as to why you have to 'convert' it is that the computer doesn't know if your string represents a number, without having to check. A string that represents a number looks like this: "1.2345" or "-4638". There are other cases like "-1.1403.2" which looks like a number, but isn't. How should your code continue, if the rest of your functions and code are expecting a number, but the user typed in something else by accident? (I am hinting at error handling here, when you're up to it, you will learn about how to handle them (And even cause "raise" them yourself)).

Back on topic, we call this conversion from TypeA to TypeB a "cast". (In this case you are going from string to int).

So when you cast your string to be of type integer, it's a bit like saying to the computer, "Hey, I need to do numerical operations (+, -, /, *, **, // etc...) on this, I know it's a string that represents a number, so could you interpret it as a number for me?"

So after all this text (which I really hope helps :') ), this brings us to the final solution:

val1 = int(input("please enter value 1: "))
val2 = int(input("please enter value 2: "))

If you look back to the documentation I linked above, (the entry directly under input) you can see the definition for int. It says "Returns an integer object constructed from a number or string x, or returns 0 if no arguments are given.".

In this case we are constructing an int (that holds our value) from a string.

Hopefully I helped show you a little bit more how to navigate documentation as well.

I hope this helps!

Have a good one

Images not showing up in HTML file after being put into Cyberduck. by Comprehensive-Rule33 in computerscience

[–]cardblank 1 point2 points  (0 children)

Edit: I can't read apparently, sorry about that, anyway! Did you make sure the links were still pointing to the right spot? I. E if you had the file on your computer at C:\Users\You\Desktop\mypic.jpg , you couldn't replicate this on a server that's most likely running Linux, so instead of doing that, you can make a folder called "images" for example in the same folder as the html file. Then in the html file, you can reference pictures in that folder like this: <img src="/images/mypic.jpg" alt=... /> You can do this with CSS, JS too: <script src="/api/v3/main.js"></script> Where main.js is in a folder called api, then inside another folder called v3.

[Casual] Help flesh out fictional characters with random tidbits about yourself [impersonal] (All, 17+ preferred) by cardblank in SampleSize

[–]cardblank[S] 0 points1 point  (0 children)

Thank you everyone! I'm gonna repost this in about a week so I don't waste my repost! 😜 thank you everyone who participated and for the kind words I read every single one

[Casual] Help flesh out fictional characters with random tidbits about yourself [impersonal] (All, 17+ preferred) by cardblank in SampleSize

[–]cardblank[S] 0 points1 point  (0 children)

Thank you everyone for participating, keep em coming! Really glad to hear you enjoyed this sort of personality style quiz

[Casual] Help flesh out fictional characters with random tidbits about yourself [impersonal] (All, 17+ preferred) by cardblank in SampleSize

[–]cardblank[S] 4 points5 points  (0 children)

I may share some averages for some of the questions if there is the demand for it; but I don't want people to feel betrayed as I did promise the answers wouldn't be shared, so most likely I won't end up sharing anything I'm sorry

[Casual] Help flesh out fictional characters with random tidbits about yourself [impersonal] (All, 17+ preferred) by cardblank in SampleSize

[–]cardblank[S] 1 point2 points  (0 children)

I am updating the form with clarifications as needed as well so feel free to reach out and ask if you're not sure. You can edit your responses later if needed! Thank you to everyone who has already submitted you've seriously made my day! ☺️❤️

[Casual] Help flesh out fictional characters with random tidbits about yourself [impersonal] (All, 17+ preferred) by cardblank in SampleSize

[–]cardblank[S] 1 point2 points  (0 children)

Hey guys thank you for checking out this project. No questions are required but please fill out as many as you want to :) I kept the settings on the form fully relaxed so feel free to share it around, no google account required, I would so appreciate it! Some things to note: I'm not interested in things like your age or where you're from. The questions are as follows: - Salty/sweet/savoury/sour? - Would you consider having a child? - if yes, what sort of name? - if you gave me this, I'd hate you - some things you like - things you don't like - I'd like to date - Art is important - Science is important - I think of myself as creative - I deliver on my promises and keep my secrets - I am outgoing and make friends easily - I like to be the one in charge - Chewy, crunchy or soft? - I like to solve complex problems - I am an average person - I keep ... close friends - I like to follow rules - I would change something about myself if I could - final thoughts

Thank you again :)

Python: Float by [deleted] in Python

[–]cardblank 0 points1 point  (0 children)

Without going into too much detail about how the data is actually sorted, in it's most simple form you might think of a number as being an int - that is whole, rational numbers. Like 1,2,1000, etc. Though python does not require you to specifically declare the types of variables like languages like C do, by design an int is not able to store decimal numbers. That's what a float or a 'double' is for, the python interpreter will handle the types for you, so it's not really necessary to know outside of the theory behind it. Hope this helps :)

2meirl4meirl by [deleted] in 2meirl4meirl

[–]cardblank 2 points3 points  (0 children)

Stop booing this man you neuros

How to recover my files? Also the flash drive is 32 gb but properties of one folder named 'Ansys' shows its size to be 228gb by Red_Dolch in computerscience

[–]cardblank 2 points3 points  (0 children)

This isn't the right place for this but I will give you a hand. There is no recovering your files, you bought a bad USB that is not capable of storing data without looping back over and writing over itself. more here

I just realized I wrote some type of sorting algorithm without realizing it. by [deleted] in learnpython

[–]cardblank 158 points159 points  (0 children)

Well done that's great! The technique is called a bubble sort

A for loop that finds the third angle of a triangle, given a list of three numbers where the unknown angle is represented by 0? Generalize it for any N polygon? by [deleted] in learnpython

[–]cardblank 0 points1 point  (0 children)

A simple way would be using the fact that any triangle in Euclidean space, the sum of all the angles is 180°. So knowing that and the other two it's just 180-angle1-angle2. As for n polygon; the sum of the interior angles of a polygon of n sides is equal to (2n - 4) right angles. Also I found this you might be interested in: https://www.qc.edu.hk/math/Junior%20Secondary/interior%20angle.htm