Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unknown Syntax Error
#1
I dont know why the first line [FIRSTNAME] is a syntax error when I run the program. Screenshot link below code.
#Password Checker
import random
FIRSTNAME = input("Please enter your first name.\n")
SURNAME = input("Please enter your second name.\n")
RANUM = random.randint(10,99)
USERNAME = FIRSTNAME[0] + SURNAME[0:4] + str(RANUM)
print ("Your user name is", USERNAME)
PASSWORD = input("Please enter a Password.\n")
USERNAMECHECK = input("Please re-enter the username to log on.\n")
if USERNAME.lower() != USERNAMECHECK.lower():
    USERNAMECHECK = input("Please re-enter the username, it is incorrect:\n")
PASSWORDCHECK = input("Please re-enter the password to log on.\n")
if PASSWORD.lower() != PASSWORDCHECK.lower():
    PASSWORDCHECK = input("Please re-enter the password, it is incorrect:\n")
    
Screenshots = Print-screen
Reply
#2
I'm not getting a syntax error with that code. How are you running it? Is there any other code you're not showing us?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Here is the full code (not finished) I dont think anything else has reliance to the code. I am using win7 with 64 bit python 3.52 idle
 
import random

#Subrounteens
def menu():
    CHOICE = int(input("Welcome,\n [1] English Questions \n [2] Math Questions \n [3] ICT Questions \n [4] Quit/Exit \nPlease enter your choice:\n")

#Password Checker

FIRSTNAME = input("Please enter your first name.\n")
SURNAME = input("Please enter your second name.\n")
RANUM = random.randint(10,99)
USERNAME = FIRSTNAME[0] + SURNAME[0:4] + str(RANUM)
print ("Your user name is", USERNAME)
PASSWORD = input("Please enter a Password.\n")
USERNAMECHECK = input("Please re-enter the username to log on.\n")
if USERNAME.lower() != USERNAMECHECK.lower():
    USERNAMECHECK = input("Please re-enter the username, it is incorrect:\n")
PASSWORDCHECK = input("Please re-enter the password to log on.\n")
if PASSWORD.lower() != PASSWORDCHECK.lower():
    PASSWORDCHECK = input("Please re-enter the password, it is incorrect:\n")
    
#Menu
#print ("Correct!\nAcessing menu")
                 
menu()
                 
    if choice == '1':
        print ("English Questions Selected")
        Q1 = input("Q1: Who is Macbeth's Wife?\n")
        Q2 = input("Q2: Who was the old king of Scotland?\n")
        print (Q1.lower,Q2.lower)

I fixed the syntax issue by using a print and variable instead of making them in one for a subroutine is there any way I could do it in one line? 
#Subrounteens
def menu():
    print("Welcome,\n [1] English Questions \n [2] Math Questions \n [3] ICT Questions \n [4] Quit/Exit \nPlease enter your choice:\n")
    choice = int(input())
Reply
#4
You're missing a close parentheses at the end of line five.

When you get a syntax error that you don't understand, always check the previous line of code and make sure everything is closed off properly.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Thanks, Stupid mistake.
Reply
#6
If it's a stupid mistake, then we're all stupid. The reason I was able to ask the right questions to identify the error is that I make that same mistake all the time.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
Yeh it just really annoys me, but the program is finished now so its all over :).


now onto the next project.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,013 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 334 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,452 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Error UserWarning: Unknown option ssl_ca_certs warnings.warn(str(exc)) Vijayaraj 0 690 Jul-11-2023, 06:01 AM
Last Post: Vijayaraj
  Code is returning the incorrect values. syntax error 007sonic 6 1,137 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,251 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,777 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,291 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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