Advertisement
Adehumble

Week4 Coding Exercise 3

Feb 22nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. #3
  2. #This program is very sensitive to user values. It is designed to keep asking for the right value in case a user enters a wrong input format without altering the program's execution.
  3.  
  4.  
  5. def split_in_two(expected_string, number):
  6.     print(expected_string[2:] if (number%2==0) else expected_string[:2])
  7.    
  8.    
  9. user_string=input("Enter any sentence of your choice: ").split(" ")
  10. while True:
  11.     try:
  12.         num=int(input("enter any num: "))
  13.         break
  14.     except ValueError:
  15.         print("Oops! That's a wrong input dear.\nYou MUST enter a whole number.\nPls, try again!")
  16.  
  17. split_in_two(user_string,num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement