I am learning python from Harvard CS50 Introduction to python course, and got this emoji question.
But got really stuck with few input values, and I am unable to understand the actual error/solve the error.
Question:
In a file called emojize.py, implement a program that prompts the user for a str in English and then outputs the “emojized” version of that str, converting any codes (or aliases) therein to their corresponding emoji.
My Code:
import emoji
a = str(input("Input: ")).strip()
b = emoji.emojize(a)
print("Output:",b)
Here’s how to test the code
`> python emojize.py
Input: :thumbs_up:
Output: ????
python emojize.py
Input: :thumbsup:
Output: ????
python emojize.py
Input: hello, :earth_africa:
Output: hello, ????
python emojize.py
Input: hello, :earth_americas:
Output: hello, ????
python emojize.py
Input: hello, :earth_asia:
Output: hello, ????
`
I am getting this kind of error
- 🙂 emojize.py exists
- 🙂 input of “:1st_place_medal:” yields output of ????
- 🙁 input of “:thumbsup:” yields output of ????
expected “????”, not “Input: Output:…” - 🙁 input of “hello, :earth_asia:” yields output of hello, ????
expected “hello, ????”, not “Input: Output:…” - 🙂 input of “:candy: or :ice_cream:?” yields output of ???? or ?????
How do I fix the errors? Can somebody please help?
1
The prompt “Input: ” and “Output: ” are printed before the actual input and output. We only need the emojized text.
Change print(“Output:”, b) to just print(b). This will print only the emojized string (b).
import emoji
user_input = str(input("Input: ")).strip()
emojized_string = emoji.emojize(user_input)
print("Output:", emojized_string)
Spoki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.