Python Forum
please help with classes and return values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
please help with classes and return values
#4
#!/usr/bin/python3

import new_module
import sys

print("""Welcome to my Classes Python program! Do you want,
        to (C)ontinue gmae or (Q)uit game? Press "1" or "2""")

answer = input("> ")

class MainProgram ():

        if answer == "1":
            print("What do you want to do?")
            print("1. Do you want to Win the game, press (1)")
            print("2. Do you want to Lose the game, press (2)")

            answer_2 = input("> ")

            if answer_2 == "1":
                print("You pressed (1)") # You Lost, go to function
                print("You win")

            elif answer_2 == "2":
              print("you pressed 2") # Won Game
              print("You lost")

            else:
                 print(f"Wrong selection, {answer_2}")
                 print("Error!")

            the_count = [5, 4, 3, 2, 1]

            for i in the_count:
                print(f"And you lose in...: {i}")

        elif answer == "2":
            print ("you pressed (2)")
            print ("You lose")

        else:
            print(f"Wrong selection, {answer}")
            print("Error!")

class Lost_Game():
    def print_function (name):
        print(f"You {name}")

        sys.exit()

class Win_Game():

    def win_function (name):
        print(f"You {name}")

        sys.exit()

var_2 = Lost_Game.print_function('lost')
var = You_Won.identify('won')
Please, could someone come up with a solution to this code so it works, for the last two classes Lost_Game() and Win_Game() classes and var and var_2 only print one line per correct each if statement above. Or explain how a Inheritance object works, thanks. Very new to Python classes.
Reply


Messages In This Thread
RE: please help with classes and return values - by jamie_01 - Jan-17-2022, 12:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to return 2 values from 1 DF that equals another DF cubangt 5 703 Oct-21-2023, 02:45 PM
Last Post: deanhystad
  [Solved]Return values from npyscreen Extra 2 1,217 Oct-09-2022, 07:19 PM
Last Post: Extra
  Parallelism with return values Plexian 7 1,579 Aug-14-2022, 09:33 AM
Last Post: Plexian
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,169 Jan-09-2022, 02:39 AM
Last Post: Python84
  Function - Return multiple values tester_V 10 4,610 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Function to return list of all the INDEX values of a defined ndarray? pjfarley3 2 2,018 Jul-10-2020, 04:51 AM
Last Post: pjfarley3
  What is the best way to return these 4 integer values? Pedroski55 4 2,605 Apr-13-2020, 09:54 PM
Last Post: Pedroski55
  Return values for use outside of function willowman 1 1,712 Apr-13-2020, 07:00 AM
Last Post: buran
  Return all Values which can divided by 9 lastyle 2 1,881 Mar-16-2020, 09:22 PM
Last Post: lastyle
  Save all values to pandas of multiple classes jenniferruurs 0 1,939 Sep-13-2019, 12:10 PM
Last Post: jenniferruurs

Forum Jump:

User Panel Messages

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