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