You cant subtract two string, cast them first to integers.

Subtract = int(enter2) - int(enter)
Answer from jabaldonedo on Stack Overflow
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-subtract-in-python
How to subtract in Python - Altcademy.com
September 5, 2023 - Subtraction isn't limited to directly stated numbers. We can also subtract variables. Let's imagine we're pirates, and we've got two chests of gold. The first chest, chest_A, has 50 gold coins. The second chest, chest_B, has 30 gold coins. # Variables and subtraction chest_A = 50 chest_B = 30 difference = chest_A - chest_B print(difference) Running the above code will give us 20. This is because we've instructed Python to calculate the difference between the gold coins in the two chests.
๐ŸŒ
Thinkincode
thinkincode.net โ€บ python โ€บ how-to-subtract-in-python
How to Subtract in Python | ThinkInCode
Subtraction in Python is achieved using the '-' operator. For instance, result = number1 - number2 subtracts number2 from number1, storing the result in the variable 'result'.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ subtract-two-numbers-in-python
Subtract Two Numbers in Python - GeeksforGeeks
July 23, 2025 - This is the most straightforward and common way to subtract two numbers. Just use the minus sign (-) between the numbers. ... Explanation: a - b subtracts 5 from 10 and the result is stored in the variable res.
๐ŸŒ
Python Guides
pythonguides.com โ€บ subtract-two-numbers-in-python
How to Subtract Numbers in Python
October 7, 2025 - In data analysis or automation scripts, you might need to subtract corresponding elements from two lists. Python doesnโ€™t support direct list subtraction, but you can achieve it using a loop or list comprehension.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ beginner input subtraction help
r/learnpython on Reddit: Beginner input subtraction help
August 14, 2021 -

Hey guys, so i'm trying to write a script where you input your age which then is subtracted from a set number (In this case it's 40)

So basically what i'd like to do is write like this

# Question
print('How old are you?:')
age = input()

x = 40
# Result
print('Hello' + ' ' + name + ' ' + 'you retire in' + ' ' + x - age + ' ' + 'years.')

This is not possible since "x" is a set number and "age" is a string which wont subtract.

I've been trying this out with float but haven't got any further than that.

Any help would be appreciated!

๐ŸŒ
Filo
askfilo.com โ€บ cbse โ€บ smart solutions โ€บ how to perform subtraction in python?
How to perform subtraction in Python?... | Filo
September 11, 2025 - In Python, subtraction can be done using the minus sign - between two numbers or variables. This is a basic arithmetic operation where the second number is deducted from the first.
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ master code online
How To Subtract In Python - YouTube
Be sure to like, share and comment to show your support for our tutorials. ======================================= Channel - https://goo.gl/pnKLqE Playlist F
Published: August 6, 2016
Views: 3K
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 5629452 โ€บ subtracting-variable-with-two-digits-in-python โ€บ 5629471
time - Subtracting "variable[#]" with two digits in python? - Stack Overflow
You can use the split method to split a string and assign the individual values to separate variables: start, end = time.split(',') timesub = int(end) - int(start) If you want to get extra fancy you could apply the int function at the same time: ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Subtracting from a deffined variable that has an intager value in a loop - Python Help - Discussions on Python.org
January 19, 2023 - Hello, I am currently working on a programming assignment for a class Iโ€™ve gotten most of the program finished. the problem Iโ€™m having is I canโ€™t figure out how to get the program to subtract from the set number of seats and save that as the remaining number of seats in that section of the theater. thus when the program loops back around that is the number of seats that are still available. this is my program so far: def main(): Hall = 300 Mezz = 100 AHT = 10 CHT = 7 AMT = 8 CMT = 5 wh...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python in-place subtraction operator
Python In-Place Subtraction Operator - Be on the Right Side of Change
July 24, 2021 - Python provides the operator x -= y to subtract two objects in-place by calculating the difference x - y and assigning the result to the first operands variable name x. You can set up the in-place subtraction behavior for your own class by overriding the magic โ€œdunderโ€ method __isub__(self, ...
๐ŸŒ
Appdividend
appdividend.com โ€บ 2022 โ€บ 03 โ€บ 19 โ€บ python-subtract
How to Subtract Two Numbers in Python
August 12, 2025 - The easiest and most efficient way to subtract two numbers in Python is to use the minus (-) operator.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-subtraction
Subtraction - Python Examples
Python Subtraction Operator takes two operands, first one on left and second one on right, and returns difference of the the second operand from the first operand.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to subtract in python
How to subtract in Python | Replit
April 14, 2026 - Learn how to subtract in Python using different methods. Discover tips, real-world applications, and how to debug common subtraction errors.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 56277238 โ€บ how-to-subtract-variables
python - How to subtract variables - Stack Overflow
You have to initialize your variables otherwise you will have errors. Be careful on your while condition you should put "and" not or.
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ programming โ€บ python
Using subtraction on variables - Python
Python 3.8.5 (default, Aug 1 2020, 10:14:08) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x = 10 >>> x -= 5 >>> x 5 >>> x -= 3 >>> x 2 >>> You can run Python interactively (as here) to experiment and learn.
๐ŸŒ
Newtum
blog.newtum.com โ€บ subtract-two-numbers-in-python
Python Program to Subtract Two Numbers with Examples
September 19, 2025 - Python uses the - operator to perform subtraction between numbers. The operation always follows the format: result = number1 - number2 ยท If number1 = 15 and number2 = 10, then result = 5. Variables store the numbers to be subtracted.