0

I'm simply wondering why my main function doesn't call my user defined methods. I'm really not sure why this isn't working and its a pretty basic question as I'm new to python so go easy. I'm using pycharm on windows

def futurevalue():
    originalPrincipal=input("Enter original Principal: ")
    interestRate=input("Enter interest rate: ")
    N=input("Enter number of periods")
    print(originalPrincipal*((1+interestRate)**N))

def futurevalueAnuity():
    originalPrincipal = input("Enter original Principal: ")
    interestRate = input("Enter interest rate: ")
    N = input("Enter number of periods")
    print(originalPrincipal*((((1+interestRate)**N)-1)/interestRate))

def main():
    kill=0
    while kill!=-1:
        menucontrol=1
        menucontrol=input("Enter \n1 to find the futuer value of a sum of 
money\n"
              "2 to find the futuere value of an anuity\n"
              "3 to quit\n")
        if menucontrol==1:
            futurevalue()
        elif menucontrol==2:
            futurevalueAnuity()
        else:
            kill=-1



if __name__=='__main__':
    main()
  • [`input`](https://docs.python.org/3/library/functions.html#input) returns a string. A string is never going to be equal to a number. – Norrius Jan 02 '19 at 01:27
  • can you elaborate? [according to this website](https://www.pythonforbeginners.com/basics/getting-user-input-from-the-keyboard) input is used for integers. What would you suggest for integers or floats? – DisplayName Jan 02 '19 at 01:30
  • cast the user input from `str` to `int`: `menucontrol=int(input("Enter \n1.... "3 to quit\n"))` – chickity china chinese chicken Jan 02 '19 at 01:32
  • Your website shows you Python 2 syntax (you can tell by `raw_input`), which is an older version due to stop being maintained in less than a year. [Check this](https://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x) on the difference in input between 2 and 3. – Norrius Jan 02 '19 at 01:32
  • @DisplayName that changed with Python 3. Raw_input is no longer valid and only input can be used, which by default reads in as a string. You can cast the inputted string to be an int. What is your program doing when you try to run it? Do you get an error message or just incorrect results? – Tyberius Jan 02 '19 at 01:35
  • thank you that worked. @Tyberius my program ran as normal, however when I input a number for the while statement the program ended; no errors – DisplayName Jan 02 '19 at 01:38
  • Aside: This code only has functions, not methods. (The difference is that methods are attached to classes). – Charles Duffy Jan 02 '19 at 01:41

1 Answers1

0

The website you linked discusses the difference between input() and raw_input() as implemented in Python 2. Your question here is for Python 3 which is implemented differently.

In Python 3, input returns a type str:

>>> age = input("What is your age? ")
What is your age? 100
>>> type(age)
<class 'str'>

So your conditions are checking str == int and none will succeed.

pstatix
  • 3,611
  • 4
  • 18
  • 40