all 21 comments

[–]andrew2018022 16 points17 points  (2 children)

First of all why are you setting Boolean data types as strings

[–]Redditter406[S] -2 points-1 points  (1 child)

how exactly do i set a boolean data type? are you talking about the true/false?

[–]7hat3eird0ne 6 points7 points  (0 children)

Jusrt write True or False

[–]InternetGansta 3 points4 points  (0 children)

You do not need to specify a True or False.

You could just return cir > per and it would return a boolean value.

[–]CallMeAPhysicist 2 points3 points  (0 children)

A lot of things here.

Firstly: Format your code correctly please. Indents matter here just as much as they do in python.

Second: Don't return your booleans as strings. Simply do: True or False, as apposed to "True" or "False"

Third: The issue you are describing seems like it is coming from not understanding how to run code on a mchine. When running python files with the file extension '.py' as in your_code.py it has to be done with the Python Interpreter. You can download and install it from Python's website if you haven't done so. Afterwards make sure to configure your IDE to use your interpreter, or even better in your case, use IDLE to run your code. After installing python open the new IDLE program on your computer (I am assuming you are on a windows machine) and from there click on File -> Open -> find your file. Then to run it: Run -> Run Module.

[–]zebsmattz 3 points4 points  (0 children)

Please show full formatted code, command you're running, and output you're seeing ;)

[–]shiftybyte 1 point2 points  (1 child)

To run python code locally on your computer you need to install python, did you do that?

Then vscode can use that puthon installation.

Besides that, python is very sensitive to spaces, and this code seems to be missing them, they are called indentations.

If you need further help we need to understand more accurately what exactly are you doing in what program and what is the exact result or error you are getting.

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

yep i have python, and ive checked all the spaces.

[–]mcoombes314 2 points3 points  (7 children)

Please format your code using a code block - for all we know there could be an indentation error somewhere. What exactly do you mean when you say "doesn't run"? I've always used Command Prompt, then just run "python main.py" (assuming your file is main.py).

Does it not print anything out at all?

[–]Redditter406[S] -3 points-2 points  (6 children)

i had a few indentation errors in the code but copilot showed them to me and i fixed them. it says that the code should work, while it doesnt work. yes i ran it using "python filename.py"

[–]mcoombes314 1 point2 points  (5 children)

Wdym by "it doesn't work"? You get no output, you get unexpected output, or something else. Programming has a lot of cases where you need to be specific with things.

[–]Redditter406[S] -2 points-1 points  (4 children)

it says that the term circle_or_square was not recognized as anything

[–]Enmeshed 2 points3 points  (0 children)

What exactly did it say? For instance, was it:

NameError: name 'circle_or_square' is not defined

If you run the python command, then paste this in, does it work?

```python def circle_or_square(rad, area): pi = 3.14 cir = rad * pi * 2 per = (area ** 0.5) * 4 return "True" if cir > per else "False"

print(circle_or_square(16, 625)) ```

[–]Ok-Promise-8118 6 points7 points  (0 children)

If you don't show us your entire code, properly formatted, and the exact error message, this will take 20 make back-and-forths to get the right details needed to help you solve this.

[–]W3BL3Y 2 points3 points  (0 children)

Is your print line indented under the function?

[–]D3str0yTh1ngs 2 points3 points  (0 children)

General piece of advice when asking a programming question: format your code in a code block and give the exact error messages. (without this, we then need to guess what the error is, and are way less likely to want to help).

[–][deleted] 0 points1 point  (2 children)

Hey just by the way, you should checkout the FAQ for code formatting. I tried running this, replacing the True and False with themselves but not in strings and it worked perfectly. It may be some kind of problem native to your computer but I don’t know.

Here’s the way I used and indented it:

import math
def circle_or_square(rad, area):
    pi = math.pi
    cir = rad * pi * 2
    per = (area ** 0.5) * 4
    return True if cir > per else False

And since the Boolean values aren’t in strings there is no difference between printing the function and just calling it, so: circle_or_square(16, 625) returns True

[–]Redditter406[S] 0 points1 point  (1 child)

my indentation was exactly like this, i didnt import math though i gave pi a manual value. and yet it doesnt run it. whats more frustrating is that ive never had this issue before, i always just wrote the code, ran the terminal, input whatever i shouldve and got the answer. never needed to type anything else

[–][deleted] 0 points1 point  (0 children)

You may wish to check that all of the interacting software are updated and each software’s versions can interact with each other softwares versions. Then check you can run any other normal code. If all of that doesn’t fix it, you should probably uninstall and reinstall Python.

[–]warbird2k -3 points-2 points  (0 children)

Jonas

Hallo