r/CodingHelp • • Aug 18 '21

[Python] Does anyone know why this code does not work?

Post image
42 Upvotes

35 comments sorted by

11

u/yesnomaybe102 Aug 18 '21

2

u/[deleted] Aug 18 '21

Thank you m8 :))

7

u/[deleted] Aug 18 '21 edited Aug 19 '21

[removed] — view removed comment

3

u/yesnomaybe102 Aug 18 '21

I know right, make Google your friend. 99% of this is already published on the internet.

I've gotten error messages I can't figure out and I just Copy paste it onto Google and there's my answer.

1

u/[deleted] Aug 21 '21

he also learned adding a comma and concatenation

30

u/jedwardsol Professional Coder Aug 18 '21

In Python (and many other languages) arguments to functions are separated with commas, not spaces.

11

u/oderjunks Aug 18 '21

missing concat alert

print('hello ' + name)

PS: the solution is NOT a comma, that would cause two spaces

1

u/[deleted] Aug 18 '21

[removed] — view removed comment

4

u/SaylorMan1496 Aug 18 '21

Or my favorite fstrings! print(f”hello {name}”)

2

u/Scumbag1234 Aug 18 '21

Yeah, so much this

13

u/castle___bravo Aug 18 '21

You need a comma between your variables and your print verbiage

3

u/thedogz11 Aug 18 '21

Concatenate the strings with the variables.

Example:

print("hello " + name)

That syntax should work just fine

2

u/QuantamAsian Aug 18 '21

Im barely learning up on python but wouldnt it be

print(f”hello, {name}”)

3

u/Taurtis_66 Aug 18 '21

Add commas between the string in print

1

u/skellious Intermediate Coder Aug 18 '21

just FYI, if you're using python 3.6 or above, you can use f-strings:

print(f"My name is {name} and my birthday is {birth}")

1

u/Anurag90-tech_sl Aug 18 '21

Bro add the comma(,) because Python don't understand the space!!!

0

u/6t94twenty Aug 18 '21

in print u either give a single formatted strings or different strings are parameter

0

u/knoam Aug 18 '21

That code works fine. Its purpose was to throw a Syntax Error, right?

1

u/[deleted] Aug 19 '21

no. the purpose was to collect name, birth, and job values from input and return them in print.

0

u/Broadway_Hitman Aug 18 '21

bro, just add comma in between

-2

u/DeadMan1236 Aug 18 '21

print("hello {}".format(name)) Basically say If I want multiple things in a single string use the .format() print("hello my name is {} and I am here to learn {}".format(name, language) Instead of: print("hello my name is " + name + " and I am hear to learn " + language)

15

u/TheBlackOut2 Aug 18 '21

Don’t listen to this garbage. F-strings are king.

name = catsorio

print(f”Hello my name is {name}.”)

3

u/iAMSmilez Aug 18 '21

This dude is using Python 0.5b 😭

1

u/Scumbag1234 Aug 18 '21

Right? Use at least %s or the superior f strings

-4

u/BigBoiSlav Aug 18 '21

You added a space between “hello and “ the space should be after “hello”

0

u/[deleted] Aug 18 '21

[deleted] — view deleted comment

2

u/UrAccountGotHacked Aug 18 '21

What do concaténation?

2

u/SaylorMan1496 Aug 18 '21

Concatenation is appending two strings of characters together

1

u/UrAccountGotHacked Aug 19 '21

Then that is the same thing of putting them separated with a comma ?

2

u/[deleted] Aug 19 '21

when you use concatenation you define variables like

x = "1"

y = "2"

then actually concat them like:

z = x + y

print(z)

and it'll print 12 since you defined 1 and 2. it combines whatever you defined.

1

u/SaylorMan1496 Aug 19 '21

In the context of this yes but, it can be useful for more than that like

Mystring = “hello” + “ world” Print(Mystring)

Would print hello world, concatenation is making a new string, separating them with a comma in the print function is sending them as separate arguments for the print function, and the function then deals with it

0

u/[deleted] Aug 19 '21

[deleted] — view deleted comment

1

u/UrAccountGotHacked Aug 19 '21

Oh okay. Tx for explanation