Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7509735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:00:33+00:00 2026-05-29T23:00:33+00:00

I have the following function in my script at the minute: def _convert_time(p): Converts

  • 0

I have the following function in my script at the minute:

def _convert_time(p):
    """Converts a percentage into a date,
    based on current date."""

    # This is the number of years that we subtract from
    # the current date.
    p_year = pow(math.e, (20.344 * pow(p, 3) + 3)) - pow(math.e, 3)

    # Returns in YYYY-MM-DD format
    date_in_history = date.today() - timedelta(days=(p_year * 365)

    # Return to the control loop
    return True

All of my functions use this system of returning True at the end, this is due to there being a central function which runs each function in sequence and check if they ran correctly before executing the next function.

However, when I run the script, before I even get to input a value to start the script, I get the following error:

 File "C:\Users\Callum\Desktop\Tempus\TempusTest.py", line 59
 return True
      ^

If I make a function in the IDLE that returns True and check it, it works fine, but for some reason it doesn’t in my script

Have you guys got any ideas on why this might be?

Thanks! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:00:36+00:00Added an answer on May 29, 2026 at 11:00 pm

    You are missing a bracket.

    You need to change this line:

    date_in_history = date.today() - timedelta(days=(p_year * 365)
    

    with:

    date_in_history = date.today() - timedelta(days=(p_year * 365))
                                                                  ^
                                                                  |
                                                           it was this one :)
    

    Q: Why was it showing an error on the return line and not there?

    Because the error is actually there.

    How could Python know that you weren’t going to give another legit timedelta argument on the next line?
    Or adding a +100 to (p_year * 365)? (like DSM suggested)

    Let’s take a look at this IDE session:

    >>> t = ('one', 'two',
    ...      'three'
    ... def f(): pass
      File "<stdin>", line 3
        def f(): pass
          ^
    SyntaxError: invalid syntax
    

    The IDE couldn’t know that my tuple was finished and I wasn’t going to add a 'fourth' element.

    You may want to play the devil’s advocate and say that I dind’t typed the comma so Python should have guessed that I was going to end the tuple there.

    But take a look at this other example:

    >>> t = ('one', 'two',
    ...      'three'
    ...      'fourth')
    >>> 
    >>> t
    ('one', 'two', 'threefourth')
    

    So as you see the error occured exactly when Python encountered a return True in a place where it wasn’t supposed to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript function: <script type=text/javascript> function quickCardRegister_OnCompleteSave() { publishContent('This is a
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
I have the following function. <script type=text/javascript> window.onbeforeprint = expandAll; function expandAll(){ $(.fieldset:gt(0)).slideDown(fast); }
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
Hi I have the following script in my form function pdf() { var frm
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
I have the following code: <script type=text/javascript> function SubmitForm() { form1.submit(); } function ShowResponse()
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.