Advertisement
Adehumble

Week4 Coding Exercise 12

Feb 22nd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. #12
  2. print("This program is written to add your current number (if greater than 5) to the list of previous numbers and delete the last number on the list otherwise.")
  3. print("|||||"*24)
  4.  
  5. #I am going to be demonstrating the functionality of this code by accepting any dynamic input from my user.
  6.  
  7. #This program won't continue execution unless the proper data type input is supplied
  8.  
  9.  
  10.  
  11. #My Function Program
  12. def push_or_pop(expected_input):
  13.     expected_list=[]
  14.     for i in expected_input:
  15.         if i>5:
  16.             expected_list.append(i)
  17.         elif i<=5:
  18.             expected_list.pop()
  19.     print(expected_list)
  20.    
  21.  
  22. #My Main Program
  23. user_list=[]
  24. while True:
  25.     try:
  26.         num=int(input("How many numbers do you want to play with? "))
  27.         break
  28.     except ValueError:
  29.         print("ooops! That's a wrong input.\nYou must enter a whole number.\nPlease, try again!")
  30.         print("|||||"*24)
  31.    
  32.    
  33. for n in range(num):
  34.     while True:
  35.         try:
  36.             user_number=int(input(" Enter those numbers: "))
  37.             break
  38.         except ValueError:
  39.             print("ooops! That's a wrong input.\nYou must enter a whole number.\nPlease, try again!")
  40.         print("|||||"*24)
  41.        
  42.     user_list.append(user_number)
  43.    
  44. push_or_pop(user_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement