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)

27th Feb 2017, 12:26 AM
Michael Addante
Michael Addante - avatar
7 Antworten
+ 6
How does the function get its parameter, x?
27th Feb 2017, 1:10 AM
Kirk Schafer
Kirk Schafer - avatar
+ 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...
27th Feb 2017, 10:04 AM
visph
visph - avatar
+ 5
have you executed this function?
27th Feb 2017, 12:42 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 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.
27th Feb 2017, 1:51 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Exactly what @Kirk said. What's the parameter x being used for?
27th Feb 2017, 2:05 AM
Don
Don - avatar
+ 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
27th Feb 2017, 3:14 AM
Michael Addante
Michael Addante - avatar
+ 1
Thank you @visph i got the code figured out now
27th Feb 2017, 2:50 PM
Michael Addante
Michael Addante - avatar