Advertisement
niwo

MagicNumber

Jun 25th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. #Magic Number program written in Python 3
  2. #written by theniwo
  3. #Define variables
  4. #Define screen scrollup
  5. def cls(): print("\n" * 100)
  6.  
  7. #Ask for input of number and tries
  8. #Set variable magic for the while loop
  9. magic=0
  10. #ask for a number between 1 and 10
  11. while not int(magic) in range(1,10):
  12.     magic=int(input('Player One, enter magic number (between 1 and 10): '))
  13.  
  14. #Ask for number of tries between 3 and 5.
  15. counts=0
  16. while not int(counts) in range(3,5):
  17.     counts=int(input('How many tries 3-5? '))
  18.  
  19. #Initialize the counter
  20. counter=1
  21. #clear the screen (Quick and dirty)
  22. cls()
  23.  
  24. while counter<=counts:
  25.     tries=counts-counter
  26.    
  27. #Ask user for a number & evaluate!
  28.     guess=int(input('Please guess the magic number: '))
  29.  
  30.     if guess<magic:
  31.         if tries>1 or tries<1:
  32.             print('Sorry, too low.', tries, 'tries left')
  33.             counter=counter+1
  34.         if tries==1:
  35.             print('Sorry, too low.', tries, 'try left')
  36.             counter=counter+1
  37.    
  38.     if guess>magic:
  39.         if tries>1 or tries<1:
  40.             print('Sorry, too high.', tries, 'tries left')
  41.             counter=counter+1
  42.         if tries==1:
  43.             print('Sorry, too high.', tries, 'try left')
  44.             counter=counter+1
  45.     if guess==magic:
  46.         print('Congratulations, that is the magic number!')
  47.         break
  48.        
  49. else:
  50.     print('Sorry, no more tries left. The number was:',magic)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement