0
volume_of_cube program keeps saying no output when trying to get user input
def volume_of_cube(x): x = int(input("Enter a Number ")) volume = x ** 3 print(volume)
7 ответов
+ 6
How does the function get its parameter, x?
+ 6
Is it all of your code?
If it is, @Jakub Stasiak suggestion is right: you don't call anywhere the function you defined... so all that do your script is to define a function which is never used... so no output ^^
The other comment about 'x' is because you don't use the value supposed being passed at argument of the function: if you don't pass parameters, you don't have to put something inside the parenthesis ( round brackets )... else you'll get an error if you call your function without argument ( one expected ), and if you pass one, you do this for nothing :P
So, to fix it:
def volume_of_cube():
x = int(input("Enter a Number "))
volume = x ** 3
print(volume)
volume_of_cube() # call ( execute ) the function...
+ 5
have you executed this function?
+ 4
@Michael - thank you for writing your thoughts; it helps us contribute. After reading @visph's answer, please consider my question a hint; as @visph shows, you are not required to 'send a value for x'. If you want to, we can help there too.
+ 2
Exactly what @Kirk said. What's the parameter x being used for?
+ 1
Parameter x is being used to take the user input to convert it to an integer as shown on line 2 of the code, and on line 3 parameter x is going to be multiplied to the exponent of 3 which the result of that is going to be held in the volume variable, and then on line 4 it will just print out volume
+ 1
Thank you @visph i got the code figured out now