Python Forum
havent programmed in years - confused by why RETURN is not returning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
havent programmed in years - confused by why RETURN is not returning
#1
haven't programmed in years
thought i would try python, wrote a script that was failing
shorten the code to just the section that I think is giving the problem

the problem being that the RETURN is not returning how/what I think it should
have researched but can't see my error

think that the RETURN should be returning values for heads_count, tails_count, x, z but it's not

import random

x = 0
x = int(x)
y = 0
y = int(y)
z = ""
z = str(z)
heads_count = 0
tails_count = 0


heads_count = int(heads_count)
tails_count = int(tails_count)


def count(heads_count, tails_count, x):

    heads_count = 0
    tails_count = 0
    
    print("in the count function")
    print(f" x is {x}")

    while x < 10:
        options = ["heads","tails"]
        result = random.choice(options)
        if result == "heads":
            heads_count += 1
        else:
            tails_count += 1
        x += 1

        print(f"heads: {heads_count} tails: {tails_count} flips {x}")
    print(f"heads: {type(heads_count)}")
    print(f" flips is {x} before leaving count function")
    z = input("return something?!?! : ")
    return (heads_count, tails_count, x, z)

    
	
def main():

    print(f"heads: {heads_count} tails {tails_count} flips {x}")

    print(f" x is {x}")
    print("in the main function")
    count(heads_count, tails_count, x)

    print("back in the main function? WHY is THIS not returning as I THINK?!!??")
    print(f"heads: {heads_count} tails {tails_count} flips {x}")
    print(f"heads: {type(heads_count)}")
    print(f"z: {type(z)}")
    print(f"your input was: {z}")


main()
thanks for any help
Reply


Messages In This Thread
havent programmed in years - confused by why RETURN is not returning - by stmoose - Mar-25-2023, 05:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String int confused janeik 7 1,139 Aug-02-2023, 01:26 AM
Last Post: deanhystad
  I am confused with the key and value thing james1019 3 1,011 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Pandas confused DPaul 6 2,628 Sep-19-2021, 06:45 AM
Last Post: DPaul
  is and '==' i'm confused hshivaraj 6 2,775 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Confused with 'flags' tester_V 10 5,007 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 2,233 Sep-26-2020, 04:42 PM
Last Post: Larz60+
  I am really confused with this error. Runar 3 3,055 Sep-14-2020, 09:27 AM
Last Post: buran
  Confused on how to go about writing this or doing this... pythonforumuser 3 2,516 Feb-10-2020, 09:15 AM
Last Post: snippsat
  'Age' categorical (years -months -days ) to numeric Smiling29 4 2,968 Oct-17-2019, 05:26 PM
Last Post: Smiling29
  Create a monthly mean column in multiple years fyec 1 4,055 Jun-21-2018, 03:57 AM
Last Post: scidam

Forum Jump:

User Panel Messages

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