Print string and integer on the same line in Python

 

a = int(input("Enter a number you want to connect: "))
b = input("Enter the input string: ")

c = int(input("Enter the position at which integer is combined with string: "))

if 0 <= c <= len(b):
    result = b[:c] +" "+ str(a) +" "+ b[c:]
else:
    result = "Position is out of range."

print(f"After combining the given integer and string\nThe output is: {result}")

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top