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
#5
Is this more like what you are trying to do?
import sys
 
class MainProgram ():
	def __init__ (self):
		self.main_loop ()

	def Won_Game(self):
		print("You won the game.")

	def Lost_Game(self):
		print ("Sorry... You lost.")

	def main_loop (self):
		print("Welcome to my Classes Python program! Do you want,")
		print ('to (C)ontinue gmae or (Q)uit game? Press "1" or "2')
		answer = input("> ")

		while True :
			if answer == "2" :
				print ("See ya later.")
				sys.exit ()
			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 == "2":
				print("You pressed (2)") # You Lost, go to function
				self.Lost_Game ()
			elif answer_2 == "1":
				print("you pressed 1") # Won Game
				self.Won_Game ()
			else:
				print(f"Wrong selection, {answer_2}")
				print("Error!")
			print("1. Do you want to play again, press (1)")
			print("2. Do you want to quit now, press (2)")
			answer = input ("> ")

MainProgram ()
Reply


Messages In This Thread
RE: please help with classes and return values - by BashBedlam - Jan-17-2022, 01:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to return 2 values from 1 DF that equals another DF cubangt 5 677 Oct-21-2023, 02:45 PM
Last Post: deanhystad
  [Solved]Return values from npyscreen Extra 2 1,206 Oct-09-2022, 07:19 PM
Last Post: Extra
  Parallelism with return values Plexian 7 1,572 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,158 Jan-09-2022, 02:39 AM
Last Post: Python84
  Function - Return multiple values tester_V 10 4,585 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,012 Jul-10-2020, 04:51 AM
Last Post: pjfarley3
  What is the best way to return these 4 integer values? Pedroski55 4 2,592 Apr-13-2020, 09:54 PM
Last Post: Pedroski55
  Return values for use outside of function willowman 1 1,709 Apr-13-2020, 07:00 AM
Last Post: buran
  Return all Values which can divided by 9 lastyle 2 1,875 Mar-16-2020, 09:22 PM
Last Post: lastyle
  Save all values to pandas of multiple classes jenniferruurs 0 1,930 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