Python Forum
my coding doesn't work plz help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my coding doesn't work plz help
#1
so basically i am trying to make a piece of coding that asks what the person wants to do. however as you can see if you try my coding whenevr it says what do you want to do, no matter what the answer, it does calculator(). please help me. p.s. i havent yet added the coding for battleships() and tictactoe(). thanks

def calculator():
#returns the result of adding num1 + num2
    def add(num1, num2):
        return num1 + num2

#returns the result of subtracting num1 - num2
    def minus(num1, num2):
        return num1 - num2

#returns the result of mutipliying num1 * num2
    def multiply(num1, num2):
        return num1 * num2

#returns the result of dividing num1 / num2
    def divide(num1, num2):
        return num1 / num2



    operation = input("what do you want to do (+,-,*,/): ")
    if(operation != '+' and operation != '-' and operation != '*' and operation != '/'):
        #invalid operation
        print("please enter a vaild operation")
        calculator()
    else:
        num1 = int(input("Enter num1: "))
        num2 = int(input("Enter num2: "))
        if(operation == '+'):
            print(add(num1, num2))
            whattodo()
        elif(operation == '-'):
            print(minus(num1, num2))
            whattodo()
        elif(operation == '*'):
            print(multiply(num1, num2))
            whattodo()
        else:
            print(divide(num1, num2))
            whattodo()

def helloeveryone():

    useless = input('Hello, how are you?')
    myname = input("What is your name? ")
    print ('Nice to meet you, ' + myname)
    myage = input("What's your age, " + myname + "?")  #finds out name and age
    
def whattodo():
    function = input('So what do you want to do? Enter A for calculator, Enter B for Battleships and Enter C for tic tac toe. ')

    if(function == 'Access secret files'):
        secretfiles()
    elif (function == 'a' or 'A'):
        calculator()
    elif (function == 'b' or 'B'):
        battleships()
    elif (function == 'c' or 'C'):
        tictactoe()
    else:
        print ('no') 
            
def secretfiles():    
         print ('lol')       

helloeveryone()
whattodo()
Reply


Messages In This Thread
my coding doesn't work plz help - by Darbandiman123 - Feb-02-2017, 05:12 PM
RE: my coding doesn't work plz help - by buran - Feb-02-2017, 05:21 PM
RE: my coding doesn't work plz help - by wavic - Feb-03-2017, 09:35 AM
RE: my coding doesn't work plz help - by Ofnuts - Feb-03-2017, 12:51 PM
RE: my coding doesn't work plz help - by wavic - Feb-03-2017, 01:53 PM
RE: my coding doesn't work plz help - by Ofnuts - Feb-03-2017, 05:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extending list doesn't work as expected mmhmjanssen 2 347 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,073 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,059 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 1,013 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 1,836 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,528 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,168 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,813 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  Process doesn't work but Thread work ! mr_byte31 4 2,782 Oct-18-2021, 06:29 PM
Last Post: mr_byte31
  Psycopg2 doesn't work with python2 MedianykEugene 3 3,097 Aug-10-2021, 07:00 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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