Asked by nick
num1 = (input("enter a number:"))
num2 = (input("enter a second number:"))
num3 = (input("enter a third number:"))
print(f"{num1}+{num2}+{num3}")
All Answers 1
Answered by
GPT-5 mini
AI
Right now your code prints the three inputs with plus signs between them as text (e.g. "1+2+3") because input() returns strings and your f-string just inserts those strings. If you want to calculate and print the numeric sum, convert the inputs to numbers first.
Simple fix (using floats so decimals work):
```python
num1 = float(input("enter a number: "))
num2 = float(input("enter a second number: "))
num3 = float(input("enter a third number: "))
total = num1 + num2 + num3
print(f"{num1} + {num2} + {num3} = {total}")
```
Shorter using map and sum:
```python
nums = list(map(float, [input("enter a number: "),
input("enter a second number: "),
input("enter a third number: ")]))
print(f"{nums[0]} + {nums[1]} + {nums[2]} = {sum(nums)}")
```
Robust version with error handling:
```python
try:
nums = [float(input(f"enter number {i+1}: ")) for i in range(3)]
except ValueError:
print("Please enter valid numbers.")
else:
print(f"{nums[0]} + {nums[1]} + {nums[2]} = {sum(nums)}")
```
If you actually intended to concatenate strings (not sum numbers), your original code is fine but you might want spaces:
```python
print(f"{num1} + {num2} + {num3}")
```
Simple fix (using floats so decimals work):
```python
num1 = float(input("enter a number: "))
num2 = float(input("enter a second number: "))
num3 = float(input("enter a third number: "))
total = num1 + num2 + num3
print(f"{num1} + {num2} + {num3} = {total}")
```
Shorter using map and sum:
```python
nums = list(map(float, [input("enter a number: "),
input("enter a second number: "),
input("enter a third number: ")]))
print(f"{nums[0]} + {nums[1]} + {nums[2]} = {sum(nums)}")
```
Robust version with error handling:
```python
try:
nums = [float(input(f"enter number {i+1}: ")) for i in range(3)]
except ValueError:
print("Please enter valid numbers.")
else:
print(f"{nums[0]} + {nums[1]} + {nums[2]} = {sum(nums)}")
```
If you actually intended to concatenate strings (not sum numbers), your original code is fine but you might want spaces:
```python
print(f"{num1} + {num2} + {num3}")
```
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.