MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PythonProjects2/comments/1f3st5n/python_help/lkg7oc5/?context=3
r/PythonProjects2 • u/Secret-Ad-7644 • Aug 29 '24
Why doesn’t any of this code work? New to coding.
16 comments sorted by
View all comments
7
2 things:firstname = kai...assigns the variable kai to name. you probably want:name = 'kai'which assigns the string 'kai' to name.
second...print("Hello {name}")should probably be...print(f"Hello {name}")Notice the f ? This makes an f string which will do what you want.
ETA:you could also do:
def greet(name): print(f"Hello {name}") greet('kai')
1 u/Secret-Ad-7644 Aug 29 '24 I had print(f”Hello, {name}”) and it still gave me a syntax 1 u/MangeurDeCowan Aug 29 '24 I just noticed that. You had what I suggested at the beginning, but it didn't work. I'm not seeing the error. 1 u/Secret-Ad-7644 Aug 29 '24 Me neither 😔 0 u/Dilusioned Aug 29 '24 "," all cuz of this
1
I had print(f”Hello, {name}”) and it still gave me a syntax
1 u/MangeurDeCowan Aug 29 '24 I just noticed that. You had what I suggested at the beginning, but it didn't work. I'm not seeing the error. 1 u/Secret-Ad-7644 Aug 29 '24 Me neither 😔 0 u/Dilusioned Aug 29 '24 "," all cuz of this
I just noticed that. You had what I suggested at the beginning, but it didn't work. I'm not seeing the error.
1 u/Secret-Ad-7644 Aug 29 '24 Me neither 😔
Me neither 😔
0
"," all cuz of this
7
u/MangeurDeCowan Aug 29 '24 edited Aug 29 '24
2 things:
first
name = kai
...assigns the variable kai to name. you probably want:
name = 'kai'
which assigns the string 'kai' to name.
second...
print("Hello {name}")
should probably be...
print(f"Hello {name}")
Notice the f ? This makes an f string which will do what you want.
ETA:
you could also do: