First Program - CalcPro.py

How do I make labels like in Batch so that I can 'go to' or initiate certain blocks of code when needed? And what is the command for goto? Whats the command for cls (or in other words clearing the screen)?

while 1:

    import math
    
    print
    print ("CalcPro - Choose a number option to proceed")
    print
    print
    print ("1)  Add ")
    print ("2)  Subtract")
    print ("3)  Multiply")
    print ("4)  Divide")
    print
    print ("EXIT - type 'exit' at any time to close.")
    print
    print
    choice = raw_input("Option --> ")

    if choice == "exit":
        ExitChoice = raw_input("Are you sure you want to exit out or CalcPro? ([Y/N])")
        
        if ExitChoice == "y":
            quit()
            
    if choice == "1":
        print
        print
        print ("Up to 3 numbers, if you want just 2 or 1, simply fill in 0 for the rest")
        print
        num1 = input("Number1 --> ")
        num2 = input("Number2 --> ")
        num3 = input("Number3 --> ")

        Solution = num1 + num2 + num3

        print
        print ("Your Solution is ") + `float(Solution)`

        raw_input()

    if choice == "2":
        print
        print
        print ("Up to 3 numbers, if you want just 2 or 1, simply fill in 0 for the rest")
        print
        num1 = input("Number1 --> ")
        num2 = input("Number2 --> ")
        num3 = input("Number3 --> ")

        Solution = num1 - num2 - num3

        print
        print ("Your Solution is ") + `float(Solution)`

        raw_input()

    if choice == "3":
        print
        print
        print ("Up to 2 numbers, if you want more, restart program.")
        print
        num1 = input("Number1 -->   ")
        num2 = input("Number3 -->   ")
    
        Solution = num1 * num2

        print
        print ("Your Solution is ") + `float(Solution)`

        raw_input()

    if choice == "4":
        print
        print
        print ("Up to 2 numbers, if you want more, restart program.")
        print
        num1 = input("Number1 -->   ")
        num2 = input("Number2 -->   ")

        Solution = num1 / num2

        print
        print ("Your Solution is ") + `float(Solution)`

        raw_input()

Suggestions/Feedback/Answers

Thank you all,

~FFS

I think you are talking about function calls.

You really don't need to clear the console screen, besides it is too OS specific.

Most programmers will tell you that goto is a bad habit. Design your program so that you don't need goto.

I think you are talking about function calls.

You really don't need to clear the console screen, besides it is too OS specific.

Most programmers will tell you that goto is a bad habit. Design your program so that you don't need goto.

GOTO issue:

The reason why I need GOTO is because the user is going to finish calculating their equations rather quickly and the program will need to loop back into it's original state (the menu screen).

CLS issue:

Well When the user finishes computing their equation(s), they need to go back to the menu right? Well in the command line console python uses (cmd.exe), it doesn't look too good when the stuff the user finished with is all cluttered and mixed with the newer computations he/she has to do. How would I get rid of the clutter w/o the CLS thing?

The reason why I need GOTO is because the user is going to finish calculating their equations rather quickly and the program will need to loop back into it's original state (the menu screen).

There is no goto int python and thank god for that.
In python you use loop/ function calls or and OOP design with classes to get where you whant in your code
This depend of how you design your program.

Think is better to show you and example than start edit you code.
Run this and you see it always loop back to menu.
Also shown you some ways to handle input error by user.
Use else and loop back one way and read about exception handling in python.
Try to understand what going on in this code,ask question if you not sure.

def add():
    '''Multiplication off numbers'''
    while True:
        try:
            my_add = input('Enter three  number to add use + : ')
            n1, n2, n3 = my_add.split('+')
            my_sum = (float(n1) + float(n2) + float(n2) )
            print('The sum is:', my_sum)
            break
        except ValueError:
            print ('Numbers only and use 2+2+2 format ')

def multicalulate():
    ''' just to show eval method'''
    my_exp = input('Enter and expression ')
    print ('The sum of expression is ', eval(my_exp))

def somthing():
    '''You can add many function and control it in main'''
    pass

def main():
    '''Main menu and info '''
    while True:
        print ('Welcome to my menu\n')
        print ('(1) Multiplication ')
        print ('(2) multicalulate')
        print ('(q) Quit')
        choice = input('Enter your choice: ')
        if choice == '1':
            add()
        elif choice == '2':
            multicalulate()
        elif choice == 'q':
            exit()
        else:
            print ('Not a correct choice:'), choice

main()
'''my output-->
Welcome to my menu

(1) Multiplication 
(2) multicalulate
(q) Quit
Enter your choice: 5
Not a correct choice:
Welcome to my menu

(1) Multiplication 
(2) multicalulate
(q) Quit
Enter your choice: 1
Enter three  number to add use + : 3+6+7
The sum is: 15.0
Welcome to my menu

(1) Multiplication 
(2) multicalulate
(q) Quit
Enter your choice: 2
Enter and expression 3+5*67/456
The sum of expression is  3.73464912281
Welcome to my menu

(1) Multiplication 
(2) multicalulate
(q) Quit
Enter your choice:

Edited 7 Years Ago by snippsat: n/a

This article has been dead for over six months. Start a new discussion instead.