CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2020
    Posts
    2

    Compiles Python code with no error but giving out no output

    Am running Python 3.8.10 in a 32-bit Windows 7 computer with only 2GB memory and no video card (not even an
    NVIDIA) - it's a two decade old netbook...

    Tried running the following code:
    Code:
    import numpy as np
    from scipy import ndimage
    
    def predict_next_string(database):
      # Split the database into a list of strings
      strings = np.array(database.split('\n'))
    
      #last_two_strings = ndimage.laplace(strings.astype(bool), mode='constant')
    
      # Check if there are at least two strings
      if len(last_two_strings) < 2:
          print ("Not enough strings in the database,")
          return
    
      # Get the second-to-the-last string in the list
      last_string = last_two_strings[-1]
    
      # Split the last string into a list of integers
      last_string_numbers = [int(x) for x in last_string.split()]
    
      # Increment each number by one and return the resulting string
      predicted_string = ' '.join([str(x + 1) for x in last_string_numbers])
    
      print("The predicted next string is", predicted_string)
     
    database = """5 3 4 5 1 2
    1 3 1 5 0 4
    2 3 0 5 1 2
    0 5 4 0 5 2
    1 1 0 5 2 4
    4 1 4 3 0 0
    4 3 3 3 2 3
    2 3 3 1 4 1
    4 2 3 3 1 1
    2 3 1 4 4 2
    0 2 3 4 2 2
    3 4 5 4 5 1
    2 4 3 1 0 2
    2 1 2 2 0 5
    4 4 1 0 1 3
    2 2 5 4 0 2
    3 2 2 2 4 3
    4 1 3 3 3 2
    5 3 3 1 3 5
    1 0 2 2 5 3
    1 3 3 5 0 2
    2 3 4 1 1 0
    0 0 4 2 4 1
    4 3 2 4 1 3
    3 4 4 1 1 4
    1 2 4 1 5 4
    5 5 4 2 0 5
    5 4 1 4 5 5
    4 4 4 2 2 0
    1 3 1 2 0 1
    1 2 4 4 5 5
    3 2 1 4 5 5
    5 1 5 2 5 4
    1 2 4 1 5 2
    5 5 4 2 0 5
    5 4 1 4 5 5 
    4 4 4 2 2 0
    1 3 1 2 0 1
    1 2 4 4 5 5 
    3 2 1 4 5 5
    5 1 5 2 5 4
    0 1 5 5 5 4
    3 3 1 5 3 5 
    """
    It is meant to predict the next string of 6 numbers from 0 to 5.

    There are no errors when I compiled it - but for some reason, it's not giving out an output.
    Name:  source code output_03202023.jpg
Views: 1331
Size:  13.7 KB

    What could be wrong with the code?

  2. #2
    Join Date
    Nov 2018
    Posts
    115

    Re: Compiles Python code with no error but giving out no output

    You define a function called predict_next_string

    But there's no apparent call to it.

    So as written, it does nothing.

    Maybe type at your >>> prompt the following
    predict_next_string(database)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured