Advertisement
Guest User

Try/ except

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import random
  2.  
  3. num = random.randrange(1, 101)
  4. print(num)
  5. guess =""
  6.  
  7. tries= 0
  8. tries_limit = 6
  9.  
  10. try :
  11.     while num != guess and tries != tries_limit:
  12.         guess =int(input("enter a digit: "))
  13.        
  14.         tries += 1
  15.        
  16.         if guess > num:
  17.             print("too high")
  18.         elif guess < num:
  19.             print("too low")
  20.        
  21.         elif num == guess and tries == 1:
  22.             print("dang, YOU ARE FUCKING SMART")
  23.            
  24.            
  25.         elif num == guess and tries == 2:
  26.             print("whAt a Genius")
  27.            
  28.         elif num == guess and tries == 3:
  29.             print("nice try!!")
  30.            
  31.         elif num == guess and tries== 4:
  32.             print("nice try!! ")
  33.            
  34.         elif num == guess and tries == 5:
  35.             print("dumb ass, THAT WAS CLOSE")
  36.        
  37.         elif num == guess and tries == 6:
  38.             print("block head")
  39.        
  40.         if tries > tries_limit :
  41.             print("YOU LOSE!!! MOTHERFUCKER")
  42.  
  43.  
  44. except ValueError:
  45.     print("that was a value error bro!!")
  46.  
  47. #whenever the Value error is run it stops the code. But I want it to continue, I have tried the
  48. #continue loop but it gives feed back that "continue is outside of loop.
  49.    
  50. #the help is how do I run it without it stopping the program when a user enters a non-int value
  51.  
  52. print("number of tries: ", tries)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement