Question: 
Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.


Model's Code:
import re

def replace_spaces(s):
    return re.sub(r'\s+', '_', s).replace('_', ' ', 1) if s else s



Sample Correct Code:
import re
text = 'Python Exercises'
def replace_spaces(text):
  text =text.replace (" ", "_")
  return (text)
  text =text.replace ("_", " ")
  return (text)


Asserts:
assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'
assert replace_spaces('The Avengers') == 'The_Avengers'
assert replace_spaces('Fast and Furious') == 'Fast_and_Furious'


Tests:
Test 1 of 3: FAIL: AssertionError()

Test 631 of 974: 470/631 (74.48494453248811%): failed