Difficulties with basic coding setup

I’m trying to follow a skillshare coding course (I’m brand new to python!). I’m trying to write some basic code in a file and have it run in the console. After the code runs, nothing appears, contrary to what the coding course shows.

The code:

def mul3(x):
  return x * 3

After running this code, the instructor is able to use the function in the console, I however am not able to type anything into the console.

There are a ton of people trying to troubleshoot this problem in the course discussion, none of us have been able to crack it.

Any help from the repl.it community would be amazing!

Thanks in advance,
Mitch

for the record, I’ve also included 2 spaces before “return x*3”

Hello and welcome to Replit Ask. :wave:

From what I can gather it seems that you want to have something like this :

x = float(input("Enter a value for x "))
def mul3(x):
  return x * 3
print(mul3(x))

I’ll try to break it down piece by piece.

First, what you have so far is fine and doesn’t need to be changed but there needs to be more added to it. Basically you’re telling the computer how to do something but you’re never telling it to actually do it.

To make the computer actually run the function you defined, we have to also call the function:

def mul3(x):
  return x * 3
mul3(1) #This is the part that calls the function

However, this still will not display anything to the console until we print it

to print it to the console we just change it to print(mul3(1))

so

def mul3(x):
  return x * 3
print(mul3(1))

Now you’ll see that it is actually multiplying x, (in this case 1,) and 3 and then printing the product to the console:

However, since you said

I’m assuming that you’re supposed to be able to change the value of x in the console?
To do this we would use an int or float input, (which just means we’re going to ask the user for a whole number or a number with a decimal) :

x = float(input("Enter a number > "))
def mul3(x): 
  return x * 3
print(mul3(x)) 
It can also be written like
x = float(input("Enter a number > "))
def mul3():
  return x * 3
print(mul3())

or

x = float(input("Enter a number."))
def mul3():
   print(x * 3)
mul3()

We ask the user to input a number, which is then stored in the variable “x” as a float. After that, we define a function called “mul3” that multiplies the input number by 3. Finally, we call the “mul3” function and print the result.

This video from the replit 100 days of code course Day 23 : Subroutines may help make things a little bit easier to understand than how I can write it.

I’m not certain if this is what you’re looking for but I hope this helps some. If not the community and I will be happy to help assist you further.

3 Likes

That’s not quite what they meant, they’re referring to the old console from what I can tell.

Do you mean basically that the course they are following is “outdated” ? (for lack of a better word.)
I apologize then for misunderstanding and compounding the issue.

1 Like

I believe that is the case, yes. Which makes sense, as probably 99% of Courses/Tutorials on Replit were made prior to the console change.

2 Likes

I see, thank you for clearing that up.
And my apologies @garlickmitchell for the non-solution.

1 Like

Thank you for taking the time to help me out, it may not be a perfect solution, but this certainly works :blush:

I’ll be using print and int to continue working though the course :+1:

1 Like

You’re welcome and it’s no problem. I’m just glad I could help kinda-sorta.
Good luck with the course and if you need anything else we’ll all be here. :smile:

Hi @garlickmitchell , welcome to the forums!
The feature was removed from the Console, so you can’t do that anymore. But wait: you can! Replit made a template for this.
Or, you can enter python -i main.py to use main.py’s code with IPython, like the actual Python console.
Hope this helps!

2 Likes