1

I wanted to make a simple program that asks the user to enter a name, then asks whether to text, call etc that person, obviously it doesn't actually do those things but thought I'd give it a go. I want to make a help section, so when the user enter the word 'help' it displays all the available commands but I want the user to be able to enter their command again, after they have seen what commands are possible, if that makes sense. I'll copy the code here for a bit of context, please don't judge my probably very inefficient code:

import time
firstname = input("what is the first name? ")
lastname = input("what is the last name? ")
action = input("what would you like to do? (type 'help' for commands) ")
while action != "call" or "text" or "video call":
    if action == "help":
        print("you typed 'help'. here is the command list:")
        print("text - text the person")
        print("call - call the person")
        print("video call - video call the person")
if action == "call":
    print("calling ", firstname, lastname, ".")
    time.sleep(1)
    print("calling...")
    time.sleep(1)
    print("calling...")
    time.sleep(1)
    print("calling...")
    time.sleep(1)
    print("call connected!")
if action == "text":
    textmessage = input("what is your message?")
    print("are you sure you want to send '", textmessage, "' ?")
    s = input()
    if s == "yes" or "":
        print("Ok, sending now.")
        time.sleep(2)
        print("Text sent.")

I tried using a while loop but that ended up just printing the 'help' information infinitely.

  • _I tried using a while loop_ Show us the actual code you tried, so we can point out what is wrong. – John Gordon Nov 24 '22 at 18:07
  • Ok have changed it – finlayearnshaw Nov 24 '22 at 18:14
  • See the accepted answer on [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response). – Charles Duffy Nov 24 '22 at 18:19
  • ...and btw, that answer has a section "Recursion Will Blow Your Stack" describing why _not_ to take the approach suggested by Lord Elrond. – Charles Duffy Nov 24 '22 at 18:19
  • `while action != "call" or "text" or "video call"` That is the wrong way to check for multiple values. See https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true – John Gordon Nov 24 '22 at 23:13

0 Answers0