Making a Slowtype function in python
Kronifer (10)

Slowtyping in Python

I'm sure you've seen projects that print out strings slowly instead of all at once. Today i'll show you how. Here is the code:

def slowtype(str):
    newstr = ""
    strcount = 0
    clearcheck = 0
    for element in str:
        strcount = strcount + 1
    for element in str:
      newstr = newstr + element
      clearcheck = clearcheck + 1
      if(strcount == clearcheck):

Lets brake it down:

first, the function accepts a string. Then, it makes 2 integers. strcount, which measures the length of the string, and clearcheck, which helps later. To figure out how long the string is, it iterates over each character in a string. Then, it moves to the second loop where the loop adds each character to a string, prints the string, increases clearcheck by 1, sleeps for 0.05 seconds, then checks if strcount is equal to clearcheck. If it is, it doesn't clear the screen. If it isn't, it clears and repeats. This used as a function will give a nice slowtype function to python code!

Here's an example:

You are viewing a single comment. View All
TigerTheCat (20)

Wow, this is awesome! I've always wanted to learn how to do this!

Kronifer (10)

@TigerTheCat No problem! Honestly, I kinda just set this up today and didn't think it would work :)

TigerTheCat (20)

What do you mean, @Kronifer? It works great!

Kronifer (10)

@TigerTheCat I set this up for a project this morning, took some troubleshooting. Also, thanks!

TigerTheCat (20)

No problem, @Kronifer! You really deserve more cycles, I don't know why nobody else is giving you any!