Python Forum
Troubleshooting simple script and printing class objects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Troubleshooting simple script and printing class objects
#1
Relatively new to Python, I’m learning to read, create, use and manipulate classes.

For practice I have begun to create a class tracking user input for a US PassPort application. In my script I have documented each code segment for readability. Here it is:
#!/usr/bin/env python3

# MIT License
# By Drone4four / Angeles4four and Daniel08 on GitHub

# The purpose of this script is to collect personal US citizen passport information

# General initilization of libraries which I may use down the road:
import random
import os

# Create a new object type called, PassPort:
class PassPort(object):

    # Initilization of special method, right?
    def __init__(self, first_name, middle_name, last_name, gender, YOB, iQ):

        # Universal class object attribute:
        species = 'homo-sapien'

        # Regular class objects:
        self.first_name = first_name
        self.middle_name = middle_name
        self.last_name = last_name
        self.gender = gender
        self.YOB = YOB # (Year of birth)
        self.iQ = iQ # (Inteligence Quotient)

    # Comparing the iQ variable among the entire citizenry:
    def iQcomparison():
        average = int(100)
        genius = int(75)
        if self.iQ < average:
            print(str("The citizen is less smart than average."))
        elif self.iQ > average:
            print(str("The citizen is smarter than average."))
        elif self.iQ <= genius:
            print(str("The citizen is among smartest of Americans."))

# Instance of PassPort:
citizen256032 = PassPort(first_name='Jon', middle_name='Ross', last_name='Dobbs', gender='male', YOB=int(1947), iQ=int(44))

# Prints specific instance to CLI (second format ), right?
print("The citizen's first name is {}. \n The citizen's middle name is {}. \n The citizen's last name is {}. \n The species of the citizen is {}.  \n The gender of the citizen is {}. \n The citizen was born in the year {}. \n And finally, the citizen has an iQ of {}." format(citizen256032.first_name, citizen256032.middle_name, citizen256032.last_name, citizen256032.species, citizen256032.gender, str(citizen256032.YOB), str(citizen256032.iQ)))

# and this iQ, as compared to other citizens, he there is a flippin {iQcomparison()}.")

# Prints specific instance to CLI (first format), right?
# print("The citizen's first name is" + citizen256032.first_name + ".  The citizen's middle name is" + citizen256032.middle_name + ".  The citizen's last name is " + citizen256032.last_name + "The citizen was born in the year " + str(citizen256032.YOB) + ".  And finally, " str(citizen256032.iQ) + ".")

'''
====== TO DO =======
* Prompt user for all his/her citizen information instead of feeding it in the script
* Rename file
* Have print statement print all the information into a flowing plain english sentence
'''
In my shell, it throws this output:
Output:
$ python3 main.py File "main.py", line 44 print("The citizen's first name is {}. \n The citizen's middle name is {}. \n The citizen's last name is {}. \n The species of the citizen is {}. \n The gender of the citizen is {}. \n The citizen was born in the year {}. \n And finally, the citizen has an iQ of {}." format(citizen256032.first_name, citizen256032.middle_name, citizen256032.last_name, citizen256032.species, citizen256032.gender, str(citizen256032.YOB), str(citizen256032.iQ))) ^ SyntaxError: invalid syntax $
I'm not sure what this shell output is trying to say. I’ve tried swapping out the str() for int() when referring to the last two class variables. I’ve also tried running the script with neither str() nor int(). Still throws an error. Any one here have an idea as to what is wrong with my program?

Here is my code on GitHub. I am accepting pull requests.

Thanks for your attention.
Reply


Messages In This Thread
Troubleshooting simple script and printing class objects - by Drone4four - Nov-05-2017, 12:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 0 82 Yesterday, 01:00 AM
Last Post: Drone4four
  Printing out incidence values for Class Object SquderDragon 3 434 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  OBS Script Troubleshooting Jotatochips 0 360 Feb-10-2024, 06:18 PM
Last Post: Jotatochips
  How can I access objects or widgets from one class in another class? Konstantin23 3 1,150 Aug-05-2023, 08:13 PM
Last Post: Konstantin23
  Troubleshooting with PySpy Positron79 0 870 Jul-24-2022, 03:22 PM
Last Post: Positron79
  Simple Python script, path not defined dubinaone 3 2,794 Nov-06-2021, 07:36 PM
Last Post: snippsat
  Troubleshooting site packages ('h5py' to be specific) aukhare 2 2,072 Nov-02-2020, 03:04 PM
Last Post: snippsat
  Class objects Python_User 12 4,624 Aug-27-2020, 08:02 PM
Last Post: Python_User
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,127 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  OOP hellp (simple class person) onit 4 2,620 Jul-14-2020, 06:54 PM
Last Post: onit

Forum Jump:

User Panel Messages

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