Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
guess the number
#4
Hey I actually just did this in a little ATM program I made what I did was defined a function for continuing and just had that executed at the end where I wanted it to happen here is what I mean:

def another():
    answer = input("Would you like to make another transaction y/n?: ").upper()
    if answer == 'y':
        active = True
    else:
        active = False
        sys.exit("Thank you for using JTM")
you could change the wording to fit your program but that was just what I found easiest and what kept me from rewriting the code a bunch of times for different options. So an example of how I used the function is here:

while active:
    print("1: Deposite")
    print("2: Withdraw")
    print("3: Balance")

    option = int(input("What would you like to do: "))

    if option == 1:
        deposite = int(input("How much would you like to deposite: "))
        print("Your deposited $" +str(deposite))
        balance = balance + deposite
        another()
so as long as the user enters 'y' when asked to continue the loop will start over otherwise but using sys.exit() I terminate the program. By the way if you do use this method be sure to just import sys let me know if this helped you out man! I am still a beginner too but feels nice to provide some insight.
Reply


Messages In This Thread
guess the number - by atux_null - Dec-05-2017, 02:09 PM
RE: guess the number - by Larz60+ - Dec-05-2017, 04:36 PM
RE: guess the number - by atux_null - Dec-05-2017, 05:30 PM
RE: guess the number - by jakegold98 - Dec-05-2017, 06:35 PM
RE: guess the number - by atux_null - Dec-05-2017, 07:22 PM
RE: guess the number - by jakegold98 - Dec-05-2017, 09:01 PM
RE: guess the number - by incineratez - Dec-06-2017, 03:47 AM
RE: guess the number - by atux_null - Dec-06-2017, 06:50 AM
RE: guess the number - by gruntfutuk - Dec-06-2017, 09:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the number game jackthechampion 5 3,314 Mar-07-2020, 02:58 AM
Last Post: AKNL
  Asking for help in my code for a "Guess the number" game. Domz 5 4,002 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Guess a number game Drone4four 4 5,471 Nov-16-2018, 03:56 AM
Last Post: Drone4four

Forum Jump:

User Panel Messages

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