Python Forum
Calling function-- how to call simply return value, not whole process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling function-- how to call simply return value, not whole process
#1
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

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())
Reply


Messages In This Thread
Calling function-- how to call simply return value, not whole process - by juliabrushett - Jul-01-2018, 12:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of function/return Paulman 6 2,402 Oct-24-2021, 11:07 PM
Last Post: Paulman
  Multiple return from function Grimmar 7 3,613 Mar-22-2021, 09:20 PM
Last Post: Grimmar
  can you call a function from a list? KEYS 20 6,340 Nov-10-2020, 06:36 PM
Last Post: KEYS
  Lambda function not return value mbilalshafiq 4 3,351 Jul-04-2020, 07:47 AM
Last Post: ndc85430
  Child class function of Log return "None" mbilalshafiq 2 2,250 Jun-30-2020, 07:22 PM
Last Post: mbilalshafiq
  Question on "define function"; difference between return and print extricate 10 4,780 Jun-09-2020, 08:56 PM
Last Post: jefsummers
  Programming (identifier, literal and function call) ledangereux 5 5,024 May-05-2020, 12:37 PM
Last Post: gumi543
  [split] problem with function return value ops 1 3,384 Apr-13-2020, 01:48 PM
Last Post: buran
  Function to return today's month, day, and year sbabu 9 4,988 Jan-28-2020, 06:20 PM
Last Post: snippsat
  Calling a function from another function johneven 2 2,898 Jul-09-2019, 12:42 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

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