0

I'm having a little trouble at my python program. It's a really simple program that you can input commands like "stats" and it returns "Weather: ", "Day: ", "Temperature: " or you can enter the command "day" to set a day, "weather" to set a weather, so you can see at "stats". On the end of every command the "command input" should appear again. When you enter the first command the command appears successfuly and the "command input" appears again (like what i want), but when you enter another command again it simples print what you just type, the command does not execute and python compiler closes.

temp = "";
wea = "";
day = "";
input1 = input("What do you want: ");
if input1 == "stats":
    print ("Day: " + day)
    print ("Temperature: " + temp);
    print ("Weather: " + wea);
    input1 = input("What do you want: ");
elif input1 == "day":
    input2 = input("Set a day: ");
    day=input2;
    input1 = input("What do you want: ");
elif input1 == "weather":
    input3 = input("Set the weather: ");
    wea=input3;
    input1 = input("What do you want: ");
elif input1 == "temperature":
    input4 = input("Set the temperature: ");
    temp=input4;
    input1 = input("What do you want: ");
elif input1 == "commands":
    print ("Commands: ");
    print ("day");
    print ("weather");
    print ("temperature");
    input1 = input("What do you want: ");
else:
    print ("Unknow Command! Try the commmand \"commands\".");
    input1 = input("What do you want: ");
2
  • There is no control structure which would re-run the initial lines of code. Look into loops, which as the while loop. Commented Nov 30, 2016 at 17:47
  • 1
    It looks like you need to put your code in a loop so that it repeats. E.g. while (input1 != "exit"): ... Commented Nov 30, 2016 at 17:50

2 Answers 2

1

Your mistakes:

1) in Python you dont need to use ; to end a statement.

2) use a while loop to continue looping

3) while loop will quit if typed "quit" (you can replace "quit" with anything else you desire).

4) Also there was a typo.

5) You do not need to write input()so many times if it's looping in while loop.

Hope this helps:

temp = ""
wea = ""
day = ""
while True:
    input1 = input("What do you want: ","\n","Press (q) to quit.")
    if input1 == "stats":
        print("Day: " + day)
        print("Temperature: " + temp)
        print("Weather: " + wea)
    elif input1 == "day":
        input2 = input("Set a day: ")
        day = input2
    elif input1 == "weather":
        input3 = input("Set the weather: ")
        wea = input3
    elif input1 == "temperature":
        input4 = input("Set the temperature: ")
        temp = input4
    elif input1 == "commands":
        print("Commands: ")
        print("day")
        print("weather")
        print("temperature")
        print("quit')
    elif input1 == "quit":
        exit()
    else:
        print("Unknown Command! Try the commmand \"commands\".")
Sign up to request clarification or add additional context in comments.

Comments

0

You seem to be missing a loop. Try something along the lines of:

temp = "";
wea = "";
day = "";
input1 = input("What do you want: ");
while not input1 == "exit":
  if input1 == "stats":
  ...
  ...

This should give you what you're looking for. See here for more on loops.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.