'program that asks the user to input a string with at least three characters and displays a new word with the word “car” after first three characters
In python how do you write a program that asks the user to input a string with at least three characters and displays a new word with the word “car” after the first and third characters in the string.
Solution 1:[1]
You can use slicing arr[p:q] would give you the slice from index p up to q - 1.
user_inp = input("Input a string of at least three chars.")
if len(user_inp) >= 3:
print(user_inp[0] + "car" + user_inp[1:3] + "char" + user_inp[3:])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | monk |
