Python Forum
Error in using the output of one function in another function (beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in using the output of one function in another function (beginner)
#1
Hello forum,

Im very much a beginner in programming. I have been spening the last couple of hours to find a solution for this simple problem. So now was the time to join the forum and get help.

I have simplified the problem area of my code in this small code. 

I want the user to make a choice in one definition and then have another definition respond to that choice. 
type in "1" should give "ONE"
type in 2 should give "TWO"

However, if I run the following code and type in "1" I will not get "ONE" as a response but "TWO" . What am I doing wrong? (why is "1" in one definition not equal to "1" in the other)?


def choice():
    choice="0"
    while choice !="1" and choice !="2":
        choice=input ("Type 1 og 2  ")
    return (choice)

def response(choice):
    if choice =="1":
        print("ONE")
    else:
        print("TWO")

choice()
response(choice)
I know I am missing something basic but I just can't figure out waht it is.
Reply


Messages In This Thread
Error in using the output of one function in another function (beginner) - by MadsPJ - Mar-13-2017, 01:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 889 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  Error with output djprasanna 1 666 Nov-28-2023, 06:40 PM
Last Post: deanhystad
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 690 Nov-23-2023, 02:53 PM
Last Post: rob101
  problem in output of a function akbarza 9 1,416 Sep-29-2023, 11:13 AM
Last Post: snippsat
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,675 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  undefined function error JonWayn 5 1,567 Sep-11-2022, 03:38 AM
Last Post: JonWayn
  How to print the output of a defined function bshoushtarian 4 1,410 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Beginner Python Error ianmac88 4 1,374 Sep-05-2022, 12:30 PM
Last Post: jefsummers
  Error in find pearson correlation function erneelgupta 1 1,967 Mar-01-2022, 03:41 PM
Last Post: stevendaprano
  how can I solve fsolve function error? troddydeeneeeeeey 3 2,587 Oct-14-2021, 07:07 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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