Advertisement
Niksko

Untitled

Apr 3rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # First things first, name your variables sensible things
  2. # This is not a joke, naming variables is one the absolute hardest parts of coding well
  3. trialTimesTable = 1
  4. randomMultiplier = randint(1,10)
  5. correctValue = trialTimesTable * randomMultiplier
  6.  
  7. # See how all of the variables above really indicate what they do. At this point, the code almost reads like plain English
  8. # Again, more variable naming
  9. practiceNumber = input("What number would you like to practice? ")
  10.  
  11. # I put brackets around the "one" or "1" here just because it's less confusing. Without the brackets it still works
  12. # but this way, I can INSTANTLY see what it's going to do
  13. if practiceNumber == ("one" or "1"):
  14.     guess = input("What is " + str(trialTimesTable) + "*" + str(randomMultiplier) + "=")
  15.  
  16.     # Notice here the ordering. It's guess == str(correctValue), not str(correctValue) == guess
  17.     # Think about how you would say this in English. "If the guess is equal to the correct value" vs.
  18.     # "if the correct value is equal to the guess". The first one makes a little more sense, because it's
  19.     # implying that the guess is the thing that could be wrong, where as the correct value is the thing that we know
  20.     # is right. Again, something subtle, but it makes the code read easier IMO
  21.     if guess == str(correctValue):
  22.         print("You are right")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement