Click here to Skip to main content
14,830,184 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Python
#new program
#objective is to make a calculator
print(str("So, this is our new brand new calculator."))
print("Now, it's time to try:-", "1.Do sum.", "2.Do substraction.", sep=('\n'))
a= float(input("""Specify a command:-
"""))
if a == 1:
    print("Here we go",)
    x = list(map(int, input("""Values please:)
""").split()))
    print("So, your values are: ", x, "If yes, then type OK, and if no, then type Not OK", sep='\n')
    a1= input("Please respond here  ")
    'ans1' == ("ok")
    'ans2' == ("not ok")
    if a1 == ("ans1"):
        print("thanks")
    if a1 ==("ans1"):
        print("sorry sir")


What I have tried:

In this program, line 14 and 15 aren't giving any effect. Means when I input "ok" or "not ok", then the program just stops like I haven't wrote anything next.
I want the print message to be shown after I respond.
How do I fix it?
Posted
Updated 5-Mar-21 6:01am
v2
Comments
Richard MacCutchan 5-Mar-21 11:34am
   
Please do what I suggested in your previous question, follow the link to the tutorial and learn the language properly. Repeatedly posting questions here on simple issues is not the way to learn.

1 solution

See the advice from @Richard-Maccutchan - work your way through The Python Tutorial — Python 3.7.10 documentation[^]

Things to take note of as you go through it:

- How to assign a value to a variable ... then check your code here
Python
'ans1' == ("ok")
'ans2' == ("not ok")
You are not assigning variables there.

- The dangers of cut & paste - these lines here do not attempt to take into account the "not ok" scenario
Python
if a1 == ("ans1"):
        print("thanks")
if a1 ==("ans1"):
        print("sorry sir")
If "ok" then you will print
thanks
sorry sir
- Note the difference between a variable and a value - "ans1" is a value, ans1 will eventually be a variable (when you fix the problem above). In other words you are checking to see if you have typed in "ans1" not "not ok"

- Which leads nicely to ... understand that "Not OK" and "not ok" are not the same. If you type in "Not OK" as you advise then the program will just terminate as you have not given it anything to do if that is typed in.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900