Python Forum
Python only outputting "101"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python only outputting "101"
#1
It first happened when following a tutorial for a basic calculator

num1 = float(input("Enter first number: "))
op = input("Enter  operator: ")
num2 = float(input("Enter second number: "))

if op == "+":
    print(num1 + num2)
elif op == "-":
    print(num1 - num2)
elif op == "/":
    print(num1 / num2)
elif op == "*":
    print(num1 * num2)
else:
    print("Invalid operator")

---------

101
Process finished with exit code 0
Now whenever I try to put anything at all, it always just gives out "101"

I even went back to previous things i'd coded, and running them now gives "101"
Reply
#2
Your code is fine, so something must be wrong with your environment.

Are you using an IDE like PyCharm? Are you sure you are executing the correct code (run does not necessarily execute the code you are looking at)?

Try executing the code in the command line / console using the same Python Interpreter as that you have configured for the project/session in your IDE.
I am trying to help you, really, even if it doesn't always seem that way
Reply
#3
What IDE do you use? PyCharm? This code is OK. I guess you have multiple files open in IDE and you run different file.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
When I create a new script with a new tab in Pycharm, the directory for the file is not updated. Any time I need to go to a new tab, I also have to edit the configurations, locate the scripts file and manually say where it is. When changing tabs in pycharm, should it not automatically change the the one that's active on screen?
Reply
#5
It's not very clear what configurations you need to edit. However I guess your problem comes from running the script from the green triangle/Run command. Note that you need to select the script from the dropdown menu next to the green triangle. I.e. it always display the last run script, not the tab currently active/code visible.

https://www.quora.com/How-do-I-run-Pytho...in-PyCharm
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading a directory and outputting as sound loungeroom 0 1,217 Jul-30-2021, 09:26 PM
Last Post: loungeroom
  Opening file and outputting its text content example leodavinci1990 1 1,874 Oct-12-2020, 05:33 AM
Last Post: buran
  Outputting Sorted Text files Help charlieroberrts 1 1,717 Jul-05-2020, 08:37 PM
Last Post: menator01
  Outputting results into other program ancient650 1 1,849 Jun-11-2019, 02:49 PM
Last Post: gontajones
  Outputting a float value in a print() statement RedSkeleton007 2 3,503 Jan-11-2018, 09:23 AM
Last Post: buran
  Attribute errors, and outputting johnnyaustin 3 3,333 Dec-09-2017, 02:58 PM
Last Post: buran
  Code is Outputting Incorrectly mikerosz94 0 2,076 Sep-01-2017, 01:28 PM
Last Post: mikerosz94
  isinstance not outputting anything mikerosz94 3 3,397 Aug-31-2017, 03:07 PM
Last Post: mikerosz94
  Repost isinstance not outputting any statements mikerosz94 1 2,914 Aug-31-2017, 12:46 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

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