Jul-01-2018, 12:55 AM
Hello,
The program I am creating will take in a value produced by the user and output both that value and the square of the value. I am to use functions for both intaking and squaring the value. However, my output returns the "Enter a number: " statement twice, leading me to believe that when I invoke the getValue() function in my "The square of the value is " statement in main I am calling beyond the value and going for the whole process of getValue. How do I forego this and simply return the value? Output is as follows currently, code below:
Enter a value: 2
The value entered is 2
Enter a value: 2
The square of the value is 4
The program I am creating will take in a value produced by the user and output both that value and the square of the value. I am to use functions for both intaking and squaring the value. However, my output returns the "Enter a number: " statement twice, leading me to believe that when I invoke the getValue() function in my "The square of the value is " statement in main I am calling beyond the value and going for the whole process of getValue. How do I forego this and simply return the value? Output is as follows currently, code below:
Enter a value: 2
The value entered is 2
Enter a value: 2
The square of the value is 4
def getValue(): val = int(input("Enter a number: ")) return val def squareValue(): val = getValue() square = val * val return square print("The value entered is", getValue()) print("The value squared is", squareValue())