/    Sign up×
Community /Pin to ProfileBookmark

Python dictionary items method, debugging phase

Hello. Please help me to find a mistake in the following Python code:

[code]
#dictionary
fcolor={“Peter”:”blue”,”Laura”:”green”,”Tom”:”brown”,”Ema”:”violet”}

#print(fcolor[“Tom”])
#print()

for k,v in fcolor.items():
print(k+” likes “+v+” color.”)
[/code]

The objective is to output a line for each name listed in this form:

(first name) likes (color name) color.

Thank you.

=====

compiler says:

Traceback (most recent call last):
File “/usr/lib/python3.8/py_compile.py”, line 144, in compile
code = loader.source_to_code(source_bytes, dfile or file,
File “<frozen importlib._bootstrap_external>”, line 846, in source_to_code
File “<frozen importlib._
bootstrap>”, line 219, in _call_with_frames_removed
File “./prog.py”, line 10
print(k+” likes “+v+” color.”)
^
SyntaxError: invalid character in identifier

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “/usr/lib/python3.8/py_compile.py”, line 150, in compile
raise py_exc
py_compile.PyCompileError: File “./prog.py”, line 10
print(k+” likes “+v+” color.”)
^
SyntaxError: invalid character in identifier

to post a comment

6 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumNov 22.2021 — I'm not familiar with compiling python but I ran your code in a script file and it worked fine.

Therefore I suspect that the error is located somewhere else.
Copy linkTweet thisAlerts:
@codewitchauthorNov 22.2021 — On a different online forum I was told that there is a mistake in invisible characters. I was advised to rewrite the last line of the code.

I think that it is the case. I write my code in a tablet word processor and copy paste it to an online compiler.
Copy linkTweet thisAlerts:
@NogDogNov 22.2021 — > @codewitch#1639721 I write my code in a tablet word processor and copy paste it to an online compiler.

Yeah, any generic word processor is likely to add stuff to the file that you don't want. Stick to a dedicated code editor for editing code. ;)
Copy linkTweet thisAlerts:
@codewitchauthorNov 22.2021 — @NogDog: Thank you for the advice. But I am on an Android device... there are apps for that, but I still have to use online compilers..
Copy linkTweet thisAlerts:
@NogDogNov 22.2021 — > @codewitch#1639731 but I still have to use online compilers

I don't think that's necessarily a problem, as long as the app you are using on the device to create/edit the code is only creating/saving plain text (i.e. no special formatting characters, converting "normal" quotes to "directional" quotes, and so forth.) For example, this is just the first match on a google search I did that might give you a good choice: https://ourcodeworld.com/articles/read/385/top-7-best-free-code-editors-apps-for-android
Copy linkTweet thisAlerts:
@codewitchauthorNov 22.2021 — @NogDog Thank you for the info.
×

Success!

Help @codewitch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...