Python Forum
[split] how to print unicode in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] how to print unicode in python?
#1
Hi, I have just started learning to program and I am using Python 3. I am learning from a book "Python in Easy Steps" by Mike McGrath all was going well until I reached chapter 2 perfroming operations on page 27 doing Arithmetic it asks you to enter the following code:
a = 8
b = 2
print('Addition:\t',a,'+',b,'=',a+b)
print('Subtraction:\t',a,'-',b,'=',a-b)
print('Multipication:\t',a,'x',b,'=',a*b)
print('Division:\t',a,'÷',b,'=',a/b)
print('Floor Division:\t',a,'÷',b,'=',a/b)
print('Modulus:\t',a,'%',b,'=',a%b)
print('Exponent:\t',a,'²=',a**b,sep = '')
File "arithmetic.py", line 2
SyntaxError: encoding problem: ascii

or it comes up with a UTF-8 error out of range 128

How do I get the priogram to print the obelus division sign?

I have tried reading about Unicode but there are so many pages about this and non of the ideas appear to be working!

How do I print the extended ASCII code set characters in Python 3?

Please help, I am as confused as hell!

Many thanks

Frank
Reply
#2
Are you sure that you use Python 3?
Here i run with your code just copy from post,no errors.
See that i also use python -V to get version.
So then when i do python arithmetic.py i am sure that use Python 3.7.
E:\div_code
λ python -V
Python 3.7.3

E:\div_code
λ pip -V
pip 19.3.1 from c:\python37\lib\site-packages\pip (python 3.7)

E:\div_code
λ python arithmetic.py
Output:
Addition: 8 + 2 = 10 Subtraction: 8 - 2 = 6 Multipication: 8 x 2 = 16 Division: 8 ÷ 2 = 4.0 Floor Division: 8 ÷ 2 = 4.0 Modulus: 8 % 2 = 0 Exponent: 8²=64
Now should also use f-string,it's the better and more modern way.
a = 8
b = 2
print(f'Addition:\t {a} + {b} = {a+b}')
print(f'Modulus:\t {a} % {b} = {a%b}')
print(f'Exponent:\t {a}² = {a**b}')
Output:
Addition: 8 + 2 = 10 Modulus: 8 % 2 = 0 Exponent: 8² = 64
Reply
#3
Hi snippsat,

I could not get your fist method to work receiving the error codes below:

Python 3.7.4 (bundled)
>>> %Run arithtest.py
Traceback (most recent call last):
File "C:\Users\frank\MyScripts\arithtest.py", line 1
E:\div_code
^
SyntaxError: unexpected character after line continuation character
>>> %Run arithtest.py
Traceback (most recent call last):
File "C:\Users\frank\MyScripts\arithtest.py", line 1
C:\div_code
^
SyntaxError: unexpected character after line continuation character

I am using python 3.6.6

It is the extended ascii set of characters I want to print and in particular the obulist division symbol/character 246

I could get your second method to work but this does not show me how to get the obulist symbol.

I have also tried the 'Thonny' which I must admit seems better than using Microsoft Notepad

I still do not know how to print extended ascii code characters though!

Thanks for your time and help though.
Reply
#4
Now you try to run code in interactivity shell,i run code form cmd or cmder(as i use) this command line in Windows
The first windows that open in eg IDLE is the interactivity shell.
When you see >>> is for shorter code testing with Enter after each line.
Example Enter after each line.
>>> a = 8
>>> b = 2
>>> a
8
>>> print(f'Exponent:\t {a}² = {a**b}')
Exponent:	 8² = 64
To write code in IDLE can post a image i have used before.

[Image: Wn7asS.jpg]
Also is this new window you can copy an paste your code in post and Run(F5) it.

Quote:I have also tried the 'Thonny' which I must admit seems better than using Microsoft Notepad
Maybe the simplest to get stated with in Windows is PyScripter
Just copy in code and push Run button,don't even need to save.

Also look at VS Code from start a really good editor,but there are some setup as see in my Thread.
Reply
#5
Thank you, I have added to your Rep :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python-resize-image unicode decode error Pedroski55 3 3,485 Apr-21-2020, 10:56 AM
Last Post: Pedroski55
  [split] Print JSON Dictionary to Excel? venukommu 1 2,295 Nov-15-2019, 09:33 PM
Last Post: micseydel
  clean unicode string to contain only characters from some unicode blocks gmarcon 2 3,978 Nov-23-2018, 09:17 PM
Last Post: Gribouillis
  Python 2 Unicode question Skaperen 2 2,490 Sep-08-2018, 06:44 AM
Last Post: Skaperen
  [split] print twice????? rafafiqui 3 2,929 Jul-19-2018, 07:23 PM
Last Post: rafafiqui
  how to print unicode in python? Skaperen 1 6,215 Jan-24-2017, 05:36 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020