Python Forum

Full Version: Invalid Syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Always check the line before:

print ("Rings " + str(rings)+ "Segments " + str(seg) + "Angle " + str(angle) + "Length" = str(seglen))
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"