Python Forum
Compiles Python code with no error but giving out no output - what's wrong with it?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiles Python code with no error but giving out no output - what's wrong with it?
#1
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:

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. (see attachment - if visible - for screenshot of output)

What could be wrong with the code?

Attached Files

Thumbnail(s)
   
Reply
#2
It’s not giving output because you never call the function.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(Mar-27-2023, 05:13 AM)perfringo Wrote: It’s not giving output because you never call the function.


So does that mean I need to insert this line in the code?

print("The predicted next string is", predict_next_string(database))
Was that correct?
That calls up the function and the database, right?
Reply
#4
A simple example of calling a function

# Basic function
def my_function():
    print('function has been called')

# Call the function
my_function()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
(Mar-27-2023, 05:18 AM)pythonflea Wrote: That calls up the function and the database, right?

That calls function and pass database as argument.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Mar-27-2023, 06:44 AM)buran Wrote:
(Mar-27-2023, 05:18 AM)pythonflea Wrote: That calls up the function and the database, right?

That calls function and pass database as argument.


But if I'm to revise the code by inserting that edit, it won't return an error in compiling?
Reply
#7
(Mar-27-2023, 06:54 AM)pythonflea Wrote: But if I'm to revise the code by inserting that edit, it won't return an error in compiling?

Why not try and see what will happen?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 387 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  Error with output djprasanna 1 552 Nov-28-2023, 06:40 PM
Last Post: deanhystad
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 491 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 2,085 Aug-13-2023, 12:16 AM
Last Post: cubangt
  Wrong type error rowan_bradley 6 1,232 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Code error from Fundamentals of Python Programming van Richard L. Halterman Heidi 12 1,715 Jul-25-2023, 10:32 PM
Last Post: Skaperen
  Syntax error while executing the Python code in Linux DivAsh 8 1,624 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Something wrong with my code FabianPruitt 5 868 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,267 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  I cannot able to see output of this code ted 1 761 Feb-22-2023, 09:43 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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