Learn to Code via Tutorials on Repl.it!

← Back to all posts
Timmy's Revenge
AsherHagler (5)

Hi, Im Asher, and I ceated this fun project for my explore math class. Here is a quick tutorial on how I made this! I created this using a-lot of if/else statements. I also added multiple endings that stop by using these codes:

Import sys
sys.exit()

This was a great way to finish off the codes! Im still new to python, and I was having trouble adding ranges. I used multiple if statements and managed to do it that way. I used these codes to allow for user input. You can make the variable anything!

variable = input("Hello there, would you like some tea?    ")
if variable == "no":
     print("Suite yourself!")
else:
     print("Sounds great! Do you prefer Earl Grey, or mint?") 
     tea = input()

You can keep doing this, but at the start, add an import with the code!

Import sys
variable = input("Hello there, would you like some tea?    ")
if variable == "no":
     print("Suite yourself!")
     sys.exit()
else:
     print("Sounds great! Do you prefer Earl Grey, or mint?") 
     tea = input()

This exits the code if you make the wrong choice. As a beginner coder myself, I used a good many if/else statements to create my dialog and to give the code-runner a better, more interactive experience. Python is very important in your indents. You need to be accurate, or else you will get many errors. The hardest part with indents and had the most errors was my number part, which ended up being a huge line of "if" statements. It looked a bit like this.

number = input("pick a number")
if number == "1":
     print("that is less than 2")
if number =="3":
     print("That is greater than 2!")
if number == "2"
     print("Your number is two!")

That is a less efficient way to do it, and i recently figured out that it is better to use this:

number = input("pick a number")
if number in range(1, 4):
     print("your number is less than 5!")
if number == "5":
     print("your number is equal to 5!")
if number in range(6, 10):
     print("your number is greater than 5!")

Range can help you get what you need done way faster! I also added a secret ending! Look in my project code to see if you can find it!

Comments
hotnewtop
ThyAphrodite (5)

This seems amazing! Keep going!

stoporinjail (136)

Pretty good for a beginner! Keep up the good work :) You can make the Guess the Number even into 1 to 100! Like for example

import random
import sys
number = random.randint(1,100)
try_no = 1
max_tries = 10
while True:
    if try_no == max_tries:
        break
    guess = input(f"This is try {try_no}")
    guess = int(guess)
    if guess == number:
        print("Correct! You win!")
        sys.exit(0)
    elif guess > number:
        print("Lower")
    elif guess < number:
        print("Higher")

The while True part makes it loop until you say break.
also, the word "True" in while True has to be capitalized!

InvisibleOne (3003)

It's a good start for your tutorial, but you should look into mark down to make it look better.
For example, instead of just pasting the code as text, put it inside of triple '`' symbols with the extension for the file at the top, 'py' and it will format your code like python, so it looks like this:

import sys
import time

def slowPrint(x, wait=.05):
  for char in x:
    sys.stdout.write(char)
    sys.stdout.flush()
    time.sleep(wait)
  print()

and not this

import time

def slowPrint(x, wait=.05):
for char in x:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(wait)
print()

```py
this will format your code
InvisibleOne (3003)

Oh yeah and you can always read the great markdown guide, you can access it by clicking on "Style your post with Markdown!" on the right bottom corner of the message box when typing a message.

AsherHagler (5)

@InvisibleOne thanks for your input! Im looking at it right now!

JWZ6 (673)

doesn't work (program)

AsherHagler (5)

@JWZ6 i found the glitch! It should work properly now!