Issue
So i have this code:
x=1
while x <= 2:
text=input("> ")
print(f"running {text}....")
x=x+0
if text=="quit":
quit()
if text=="clear":
import os
os.system("clear")
So i wanted to know if there was a way for me to tell python "hey could you please not print "running..." on these two words, clear and quit?" And well i tried all i could think of, and it either: ignored it, or it threw up an error telling me to screw off, could you guys maybe help me?
Solution
It's pretty similar to fizzbuzz. That's probably why it seems hard to come up with a "nice" solution.
text=input("> ")
if text != "quit" && text != "clear":
print(f"running {text}....")
I was just about to add an alternative and better approach with elif
and else
, but @milanbalazs was faster. :)
When you expand the application, this approach might be a good option:
nonprintables = ["quit", "clear"]
while x <= 2:
text=input("> ")
if not text in printables:
print(f"running {text}....")
Answered By - klutt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.