I'm a fucking brainlet who is trying to learn python. Why doesn't this work? it returns the BMI, and the message...

I'm a fucking brainlet who is trying to learn python. Why doesn't this work? it returns the BMI, and the message, but it won't return the variable myName.

Attached: brainlet.png (665x382, 40K)

Well you didn't put print(myName) in the last elif block

Retarded cremefag

shouldn't you be passing the variables as parameters to the function?

Here's what happens if I try to put a name.

If I use a class name, like int, it seems to kind of work.

Attached: brainlet 2.png (1366x768, 67K)

Learn the syntax.
Either write
if bmi > 25:

or
if(bmi > 25):

>Hungry skeleton at

OK

Why isn't it printing myName

Attached: brainlet3.png (1366x768, 82K)

Have you not learned what scope is yet?

hungry skeleton detected

Underweight =

I don't know, should I be?

i've watched about 30 minutes of some pajeet on Youtube and read a bit of python for beginners online. I figured it was better to dive straight in. Reading is for fags.

Run it as python3 and it will work.

If you want to keep using python2, change the input() calls to raw_input()

Delusional fatty detected

Aids medication makes euros thinner, I take it.

Have you? There are no scope errors with what he's doing

do you have aids?

Does python fucking use global variables in functions if they're already declared as local variables? Why would it automatically know what myName is without putting it in as a parameter?

yeah they're global

>Does python fucking use global variables in functions if they're already declared as local variables?
No, but they aren't defined as local variables, only global ones.
>Why would it automatically know what myName is without putting it in as a parameter?
Because it's in global scope. Are you retarded?

The last block does not have print(myName) idiot

>because they're already in global scope
Well that's just silly. No wonder Java is a better language

I can't tell if you're being retarded on purpose or not

But the others do, and won't print. See

typecast your inputs

The answer is in You're using python2's input function, which tries to evaluate input as an expression. Either use raw_input() which returns a string, use python3's input() which returns a string, or always pass your name in quotation marks on the command line

Shot, you guys were right. Assumed ubuntu came with python 3, but it's python 2. Thanks guys.

Sorry, that didn't work. Now I'm getting a tab indentation error?

Attached: brainlet4.png (1366x768, 147K)

Yes, Java, the language where the enterprise pajeets likes to use singletons, which is global variables

It does, but it's not default. Try:

python3 bmicalc.py

this holy shit I cant believe it took Jow Forums this long to figure it out.

based chocposters.

why the fuck are you not using a graphical ide, like spyder? They offer pretty decent debuggers.

Man you don't even need the function to perform what you're doing there. Use function when you want to pass in arguments and return variables

There is no point in using an IDE if you're doing babby level entry programming like this.

Attached: [アニメ BD] トップをねらえ! GUNBUSTER 第05話「お願い!!愛に時間を!」(1432 (1432x1080, 158K)

if you're going to insist on using nano, read the nanorc man page and enable auto-indent and shit in your ~/.nanorc (and put set nowrap somewhere in there so your code isn't chopped in half with newlines in the middle of it based on screen-width)

I have eric, but like I said I'm fairly new to this.

Why are my tabs inconsistent? They look like they should according to the python for beginners book I'm reading.

Attached: brainlet5.png (1366x768, 144K)

Bad bait
Call the function with desired params

Sorry,that isn't aligned. I pressed space. Still no change.

Attached: brainlet6.png (1366x768, 151K)

Listen up creamfag, literally just copy and paste your first 4 lines into your function, call it, and be on your way.

Stop being such a fucking retarded creampuff

how come beginners confuse printing and returning, I've seen multiple people do this

ding ding ding!
I assume you don't want 3 lines. Instead, do print("Your BMI is "+ bmi +", "+ myName + ". ... wow, you're fucking fat!") for one line.

I don't know why you're getting an indentation error, but I don't know your IDE

I'm not trying to multiply a fucking string you I'm trying to multiply two fucking numbers. You did it fucking earlier

Why isn't it doing it now?

Attached: brainlet 7.png (1366x768, 169K)

Yes you are, anything brought in through input is a string and needs converted for math functions...

You should make it a habit to read any function's doc string before using it.

You should learn a different language.
When the D community is split into 2 runtimes everyone in /dpt/ shits on them.
When Python has Pajeets devving in both 2 and 3 nobody seems to care

the absolute STATE of the python language

I don't know a lick of Python, but can't you just cast it?

you're comparing a string to a number

Thanks man

But it exactly what i wanted here, what changed?

Attached: brainlet8.png (1366x768, 186K)

In that example I was comparing 83.3 to 1.97, which worked previously. Why are they now strings instead of floats?

If you want to do math with inputs shouldn't they be converted with int()?

10/10 troll you've been given the answer and aren't following it.

Cast weight and height to an integer. They are currently strings.

Change your bmi line to this and notice how it will work.
bmi = int(weight_kh) / (int(height_m) * int(height_m))

>what changed?
See Python2's input() function EVALUATES the input. If you pass it a numeric string, it will treat it the same as a number placed directly into the source code. Python3's input() function just always returns a string. You can convert it with a casting function.
Your bmi calculation should be
bmi = float(weight_kh)/(float(height_m)**2)

>all the people ITT helping this fucking retard instead of telling him to Google it

You're contributing to his low IQ.

>those redundant prints

We've said this to user, but user doesn't understand. user should have stackoverflowed how to do that by now and realized that he/she should be doing something like height = int(input("What is your height?"))

This works because user would be converting the input string to an integer right off the bat.

Afterward, user's variable BMI will be an integer, because it was declared using math. To fix this, user would do something like BMI = str(BMI), or else the string concatenation will throw more errors.

These are small errors that are easy to make as a beginner, but you do need to take time to learn the fundamentals of programming. Every variable has a type, and this needs to be considered in the planning phase of any program.

Also, use that int conversion for all ints, or use it as did.

Python is a fucking mess

I swear to god I'm going to fucking kill myself.

Thanks for everyone helping though, appreciate it.

Attached: brainlet9.png (1366x768, 171K)

retard

What that means is that you are trying to use a float in a print statement. Trace the code and find the float/int and convert it to a string before using it in a print. To fix this with one line, you will do x = str(x) where x is the variable in the print statement.

The variable is [spoiler]bmi[/spoiler], but you should try to trace your code first.

(oops)

Fuking install geany on that shit. its way easier

Seriously, thanks so much. It makes perfect sense now. Appreciate all the time you took.

Attached: brainletredeemed.png (1366x768, 162K)

Pajeets first code.

myName = input("What is your name: ")
weight_kh = input("What is your weight in kg?: ")
height_m = input("What is your height in meters?: ")
bmi = float(weight_kh) / float(height_m) * float(height_m)

def bmi_calc():
print("%s your BMI is %f %s" % (myName, bmi, ("fat neckbeard" if bmi > 25 else "almost fat" if bmi > 20 else "skinny fuck")))

you probably COPY PASTED you mongrel. re-write the code

this

Python's ternary operations are a fucking mess that shit is illegible.

Not a problem. If you're interested in making the BMI output look cleaner, try splicing. I haven't done that in a while, but I think you'd replace bmi in your print statements with bmi[:3] or whatever number you're looking for as the rounding. Alternatively, you could round the number before converting it to a string.

This is why Python is bad for learning.

This is a better way to write print statements with variables, but please explain it to user. It hurts the coding culture when we reinforce black box learning imo.

What would you suggest? The only reason I chose python is a bunch of pajeets I was watching said it was the best first language on youtube

No. whatever you may hear. the best to start are C/C++ or Java. There's just no other way around it

It's a really good first language, but it depends on the person. I personally had the most success with PBasic 2.0 and a microprocessor. Python is still fine, and user is just being a dickhead.

>forced op to install a bloated ide for his 5 lines of python
well done

IDE's don't really come all that bl

this is garbage dont do this

dont you need to use the float() function to convert the string values from the input to float?

welcome to the bread

is this the best that Team Creme has to offer?

Get out of here butterlicker.

Almost literally anything else. Even Ruby, a language that is basically useless once you use anything else, is better for learning.
Be hardcore and do C/C++, or use C#/Java, or fuck, even Golang would be a great place to start. They're all strongly typed, have non-whitespace syntax, and have a christload of learning material.
Python is highly idiosyncratic and abstracts a shitload of stuff away from the user, not to mention is missing a lot of basic language features like Switch Cases.

Just not Python. I've been teaching the last 3 years while working on my PhD and holy fucking shit every single student that comes to me with a boatload of issues has almost always started on Python.

I'm not. A lot of people have had success with Python, but so, SO many more have had these endless, needless struggles with basic shit because Python by design is so retardedly fragile.

Ruby is a language for SJW's and retards but it does a lot of magic in the background to make it just work for retards because if you make a stupid mistake it takes a guess at what you meant and runs anyway. Something that's nice for beginners but terrible for any serious work - as you get a bunch of obscure errors second only to Javascript's implicit conversion bullshit.

Python is fine once you understand the basics and just need to get some shitty thing working for your compsci class.

>Now I'm getting a tab indentation error?
Guess what a tab indentation error means?

Also
>nano
>in year of our lord, two thousand eighteen
Stop, just stop. Just install Geany like some anons suggested and stop trying to look like a 1337 h4x0r.

>Ruby is a language for SJW's and retards
Only in the sense that it's popular for Rails. Using it under Docker and Chef deployment operations has a ton of flexibility and power.

Ruby is better (not great, but better) than Python because:
No whitespace syntax
EVERYTHING is an object
Clean, clear, and concise Module/Class/Public/Private/Scoped-Variable sigial and definitions.
Introduces anonymous lambda expressions very early
Introduces iterables almost immediately
Introduces ranging and slicing almost immediately
Does not require you to define everything with a type, but *does* require you to make explicit conversions of things.

That last part is particularly important because new programmers don't like having to figure out what variable type they're going to be dealing with immediately, but may have an idea of what they're expecting when calling it later. So getting them used to doing lots of .to_s or .to_i or to_list and etc calls is important, as you have to make these calls all over the place in other languages like Java, and it's important to solidify the idea of "This is an object, I need it is form X"
Python doesn't enforce any of that, it implicitly and dynamically tries to get shit all over the place, which leads to bizarre issues of "this came in as a string, why is it printing as an object now?"

>reading is for fags
Brainlet, you would have solved this by yourself if you read a fucking book.

>I have never written anything more than FizzBuzz in Ruby - the post.

Just been playing around with what you taught me, it's super simple once you get your head around it. Seriously, thanks again, I'm really enjoying learning.

Attached: brainlet 10.png (1366x768, 93K)

Just do this you nigger

Attached: file.png (654x465, 43K)

If you don't care about efficiency that much, just use float all the time. So you won't have issues

Take a look at your code. You are always printing the bmi and name, why put three separate times when you can do it once?

Funny, that was also my first program when I started programming on the TI-83+ way back in 2003.

Yes, that's the point of a function right? y(x)
Makes it much more reusable, otherwise there's not point in having the damn thing.

Use .format to print variables in quote blocks.

who the fuck its teaching those cremetards to overindent?

Oh my god you fucking brainlet, just use raw_input instead of input on myName

Hey CK Dojo! I used to work at Google because they thought I was a transgender female but now I work in this YouTube channel

>not just using a switch/case
you dont even need a function for this

>evaluating input by default
>types hidden from the programmer
>python 2 vs python 3 bullcrap
>indentation errors
Is this the true power of python?

>python
>switch
succ my cocc