+ 6
How to take unicode input here on Sololearn?
There are solutions for printing unicode letters like ü in our Sololearn console codes. But what do we do with user input? Whenever I input() German umlauts, I get an error.
14 odpowiedzi
+ 4
HonFu
With difficulty.
I recently made a code using unicode in C++.
Later helped someone generate Farsi characters in Python.
It took time to find a method and format that worked.
Examples:
Python:
https://code.sololearn.com/cNtlKBbnBQPn/?ref=app
C++:
https://code.sololearn.com/c5z7Wfic8yWU/?ref=app
+ 4
Hm, interesting (I don't really get it).
So no easy way around this?
Why is this even a problem? Shouldn't Sololearn's PC's be able to process unicode voluntarily?
+ 4
/*
HonFu , I Know this question is 24 days old but I should say that now it's possible.
Since SL started using Linux you can use emojis without any external libraries.
Manual your C++ code will no longer work. io.h and fcntl.h is windows specific. however you can keep it unchanged to show how it works on windows. 🤓
https://www.sololearn.com/post/166812/?ref=app
Try below code :
*/
#include <iostream>
int main() {
std::string emoji="😸"; //😸 if no input
std::cin>>emoji;
std::cout<<emoji;
return 0;
}
#python
emoji = input('enter emoji ') or "😸"
print(emoji)
+ 3
A few minutes to make a sample.
The C++ example does not need the parameter pack.
+ 2
HonFu
Who knows. The non web codes, do not work like they do in IDEs.
+ 2
Hm, but how can you make use of that with input which seems to come as str? 🤔
+ 2
HonFu
I currently would not make a project with unicode input.
If the input is critical, I feel the result may not be good.
+ 2
Can you post a MWE? My keyboard is Spanish/English so I don't run into troubles.
+ 2
Diego
import sys, codecs
sys.stdout = codecs.getwriter('utf-16')(sys.stdout.buffer, 'strict')
print('ü')
print(input()) # input 'ü'
Without the encoding lines, only one line works; outcomment them, suddenly only the other works.
+ 2
Oh wow, that's an actual, tangible improvement for a change. Nice! :)
+ 1
Thank you for waiting since you needed a python version.
Python:
https://code.sololearn.com/clG1q5b5nIr9/?ref=app
+ 1
HonFu
Unfortunatly I do not know how it works, yet.
I found mixed answers online.
C++ version:
https://code.sololearn.com/c8UOZ3E0s3HL/?ref=app
+ 1
You can try "\U" or "\u" before the string. Both will help. But the first one is for 16 bit hexadecimal value and the second one is for 16 bit hexadecimal value. And it's a python function.
0
cv