Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid Syntax error
#1
I have updated the code and added the capability to calculate multiple rings but keep getting a syntaxerror on the last line. Any suggestion welcome.
"""
Written by: Dave Taylor
Date: September 20, 2020
Python Version 3.8

Program to aid in the design of Segmented wood turnings.
SegCalc is designed to create the angle and segment length of a given
number of rings at a given diameter starting at the base of the
bowl. Output is through a CSV file which if the installation
is using Excel will create a printed output.
"""
import csv
file_name = input ("enter the name of the file to be created .txt ")
rings = float (input ("enter the number of segment rings"))
with open ("c:/user/detay/pycharmprojects/segcalc.csv","w", newline="") as f:
    datainput = csv.writer (f , delimiter = ",")
    datainput.writerow (["Ring # ", "Sebments", "angle", "Length"])
while rings >0:
    seg = float(input ("enter the number of segments "))
    dia = float (input ("Enter the diameter of the ring "))
    cir = dia * 3.1416
    angle = 360/(2*seg)
    seglen = cir/seg
    with open ("c:/users/deta/pycharmprojects/segcalc.csv" "a", newline = "") as f:
        datainput = csv.writer (f , delimiter = ",")
        datainput.writerow ([rings, seg, angle,seglen])
print ("Rings " + str(rings + "Segments " +  str(seg) + "Angle " + str(angle) + "Length" = str(seglen))
rings -=1
Reply
#2
Always check the line before:

print ("Rings " + str(rings)+ "Segments " + str(seg) + "Angle " + str(angle) + "Length" = str(seglen))
Reply
#3
With Python 3.8 version what you are using it's much easier to use f-strings:

# "Rings " + str(rings + "Segments " +  str(seg) + "Angle " + str(angle) + "Length" = str(seglen)

f'Rings {rings} Segements {seq} Angle {angle} Length = {seqlen}'
Or you can consider taking advantage of f-string debugging feature:

>>> my_string = 'Hello'
>>> my_integer = 42
>>> f'{my_string=} {my_integer=}'
"my_string='Hello' my_integer=42"
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,183 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 388 Jan-19-2024, 01:20 PM
Last Post: rob101
  error: invalid command 'egg_info' TimTu 0 958 Jul-27-2023, 07:30 AM
Last Post: TimTu
  Syntax error while executing the Python code in Linux DivAsh 8 1,588 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,230 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  print(data) is suddenly invalid syntax db042190 6 1,202 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  syntax error question - string mgallotti 5 1,318 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,259 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 11,040 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Syntax error tibbj001 2 893 Dec-05-2022, 06:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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