Python Forum
"SyntaxError: invalid syntax" running code in Doing Math With Python b
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"SyntaxError: invalid syntax" running code in Doing Math With Python b
#1
Hello, I'm scratching my head trying to get the code in the book Doing Math With Python by Amit Saha on page 9 to work.

Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>> from fractions import Fraction
>>> try:
    a = float(input('Enter a number: '))
    #keyword except doesn't un-indent, I have to force it with a backspace
except ValueError:
    print('You entered an invalid number')
    Enter a number 3/4
    
SyntaxError: invalid syntax
>>>
What am I doing wrong? Wrong python version?

Regards,

David
Reply


Messages In This Thread
"SyntaxError: invalid syntax" running code in Doing Math With Python b - by saucerdesigner - Nov-03-2020, 03:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 642 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 387 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 522 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,795 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  Syntax error while executing the Python code in Linux DivAsh 8 1,606 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 1,888 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Code is returning the incorrect values. syntax error 007sonic 6 1,231 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  print(data) is suddenly invalid syntax db042190 6 1,204 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  Math python question Deonvek 6 1,152 Apr-05-2023, 09:27 PM
Last Post: deanhystad
  Code running many times nad not just one? korenron 4 1,364 Jul-24-2022, 08:12 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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