A python program to accept 3 integers in the same line and display their sum ||#shorts #programming

preview_player
Показать описание
Here's a Python program that accepts 3 integers in the same line and displays their sum:
code:

nums = input("Enter 3 integers separated by space: ")

# Convert the string values to integers
num1 = int(num_list[0])
num2 = int(num_list[1])
num3 = int(num_list[2])

# Calculate the sum
sum = num1 + num2 + num3

# Display the result
print("The sum of", num1, "+", num2, "+", num3, "is", sum)

Explain Code:

In this program, we first accept the input from the user using the input() function. The user is prompted to enter 3 integers separated by space.

Then, we split the input string into a list of individual values using the split() function. We convert the string values to integers using the int() function and store them in separate variables.

Next, we calculate the sum of the three numbers using the + operator and store it in a variable called sum. Finally, we display the result to the user using the print() function.

#learn_programming_1200 #coding #python #youtubeislife #subscriber #youtubeguru #youtubecontent #newvideo #subscribers #youtubevideo #youtub #youtuber #youtubevideos
Рекомендации по теме
visit shbcf.ru