Learn to Code via Tutorials on Repl.it!

← Back to all posts
Make a console!! No config or js. Python!! really simple.
dabombdgdzjr (107)

Welcome one and all!

Im going to show you how to make a console that can actually make files!!!!

setup

So first you want to do:
import os
while True:
console = input(">>> ") # you can put any text you want there

basic commands

Okay, its time to add your first command!
echo("text")

So first add:
import os
while True:
console = input(">>> ")
if "echo" in console: # if echo is in the console...
readfinal = console.split('"') this variable is splait between double quotes, you can change this to also single quotes
print(readfinal[1]) # print it
Now run the code and youll see it will do this:
echo("hi")
hi
If you see this, Congrats! If not, maybe review the code.
Now, to add a simple clear function
add this to the while True statement:
elif console == "clear":
os.system("clear")
now run it again and say
clear
it should clear the console!!
Now for adding the files
so add this:
elif console == "makefile":
txtfile = input("Name of file (if file is not real, a new file will be created)\n")
file = txtfile
os.system("clear")
if file == 'main.py':
print("error. cannot rewrite main.py")
else:
file = open(txtfile, 'w')
while True:
write = input("enter anything to write\n(say .exit to exit)\n\n")
os.system("clear")
if write != '.exit':
file.write(write)
else:
file.close()

break
That should do it! Now to run them
elif "python" in console:

os.system(console)

else:

print("undefined command:", console)

Thats it!
The complete code should look like this:
import os
while True:
console = input(">>> ")
if console == "clear":
os.system("clear")
elif "echo" in console:
readfinal = console.split('"')
print(readfinal[1])
elif console == "makefile":
txtfile = input("Name of file (if file is not real, a new file will be created)\n")
file = txtfile
os.system("clear")
if file == 'main.py':
print("error. cannot rewrite main.py")
else:
file = open(txtfile, 'w')
while True:
write = input("enter anything to write\n(say .exit to exit)\n\n")
os.system("clear")
if write != '.exit':
file.write(write)
else:
file.close()
break
elif "python" in console:
os.system(console)
else:
print("undefined command:", console)

Also...

Someone please tell me how to do multiline code style in markdown, thx!

credits

Credits to @Code1Tech for the readfinal code
Credits to me, @dabombdgdzjr for being cool and making this
Credits again to @Code1Tech for the making file code.

KTHXBYE

Commentshotnewtop
Wumi4 (288)

Just use three '`' in Makrdown to make a code block.

This is an example code block written in Rust, you don't need to understand what it does:

// Main function
fn main() {
  // Init x = 60, an int and mutable
  let mut x = 60i8;
  // Init borrowed_var borrowed the value
  // From x
  let borrowed_var = &x;
  // Print 2 of them
  println!("x = {} and borrowed_var = {}", x, borrowed_var);
  // Update x = 10
  x = 10;
  // Print two of them once again
  // To see the changes
  println!("Now, x = {} and borrowed_var = {}", x, borrowed_var);
}
dabombdgdzjr (107)

@Wumi4

print("thx m8")
print("ebic")
dabombdgdzjr (107)

did u like the tutorial @Wumi4

Wumi4 (288)

@dabombdgdzjr

Y E S

Although it sucks lol
dabombdgdzjr (107)

hope u like the next one ig :( @Wumi4

dabombdgdzjr (107)

Sorry for the horrible md pls someone help if u see this