Question: Write python program to swap comma and dot in a string. The program should take input from the user (assume that this input will contain

Write python program to swap comma and dot in a string.

The program should take input from the user (assume that this input will contain only one comma and one dot), it should swap comma and dot in the given input then print the result.

Examples:

"32.054,23" "32,054.23"

"4.663,17" "4,663.17"

Note:

- Please use this program and try to add things to this. I already wrote half of this program please try to use this don't rewrite everything.

Program

string = input('Enter a number that contain only one comma and one dot: ')

dot_loc = string.index(".") comma_loc = string.index(",") first_part = string[0: dot_loc] second_part = string[dot_loc + 1:] new_string = first_part + "," +second_part

print(new_string)

Output

Enter a number that contain only one comma and one dot: 32.054,23

32,054,23

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!