Returning a String Endless Times

euginya
command = input("> ")
started = False

while True:
if command == "start":
  if started:
   print("car has already started") 
  else: 
      started = True
      print("car started")
elif command == "stop":
    if not started:
        print("car has already stopped")
    else:
        started = False
        print("car is stopped")
elif command == "quit":
    break

it renders "car has already started" infinite time when i state "start" and likewise with other inputs. how do i inhibit this? would be very helpful if you explain it in beginner terms, thank you!!

Sujay

Male sure to add the input to thie while loop. In your case, it is just taking one input and then the value of command is fixed. So, it is an infinite loop.

But when you change the location and keep it inside the loop, every time it asks for the input, the value of command will change.

Also, .lower() will convert the input to lower case to remove case insensitivity

started = False

while True:
    command=input('>> ').lower()
    if command == "start":
        if started:
            print("car has already started") 
        else: 
            started = True
            print("car started")
    elif command == "stop":
        if not started:
            print("car has already stopped")
        else:
            started = False
            print("car is stopped")
    elif command == "quit":
        break

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Returning the words from a string that occur a number of times or more in python 3?

From Dev

.NET how to prevent calling a method returning a string multiple times

From Dev

Returning a string that repeats 1 more character than the number of times each character shows up in a string

From Dev

Controller returning value multiple times

From Dev

Debounce function returning multiples times

From Dev

Python 3.x: Finding substring from a string -- Outputs Endless

From Dev

Serial construction of a string in for-loop with mempcpy leads to endless recursion

From Java

Returning the number of times a number appears in an Array?

From Dev

Binary search returning wrong answer many times

From Dev

SELECT returning X times the same results

From Dev

Facebook SDK returning incorrect times for events

From Dev

ACF returning checkbox values multiple times

From Dev

Java for loop returning the same number multiple times

From Dev

Map is returning the items of an array multiple times

From Dev

PHP MYSQL Returning Result Two Times (Double)

From Dev

foreach returning the same row 4 times codeigniter

From Dev

iSQL Query Returning Value Multiple Times

From Dev

Print string multiple times

From Dev

getElementById() not returning correct string

From Dev

Functions Returning A String - Swift

From Dev

Returning or Pushing String Char

From Dev

NSubstitute returning empty string

From Dev

Retrofit is not returning full String

From Dev

Function returning pointer to string

From Dev

Compiling string and returning it as a vector

From Dev

String method returning null

From Dev

swift function not returning string?

From Dev

Why the function is not returning the string?

From Java

Method not returning a string

Related Related

  1. 1

    Returning the words from a string that occur a number of times or more in python 3?

  2. 2

    .NET how to prevent calling a method returning a string multiple times

  3. 3

    Returning a string that repeats 1 more character than the number of times each character shows up in a string

  4. 4

    Controller returning value multiple times

  5. 5

    Debounce function returning multiples times

  6. 6

    Python 3.x: Finding substring from a string -- Outputs Endless

  7. 7

    Serial construction of a string in for-loop with mempcpy leads to endless recursion

  8. 8

    Returning the number of times a number appears in an Array?

  9. 9

    Binary search returning wrong answer many times

  10. 10

    SELECT returning X times the same results

  11. 11

    Facebook SDK returning incorrect times for events

  12. 12

    ACF returning checkbox values multiple times

  13. 13

    Java for loop returning the same number multiple times

  14. 14

    Map is returning the items of an array multiple times

  15. 15

    PHP MYSQL Returning Result Two Times (Double)

  16. 16

    foreach returning the same row 4 times codeigniter

  17. 17

    iSQL Query Returning Value Multiple Times

  18. 18

    Print string multiple times

  19. 19

    getElementById() not returning correct string

  20. 20

    Functions Returning A String - Swift

  21. 21

    Returning or Pushing String Char

  22. 22

    NSubstitute returning empty string

  23. 23

    Retrofit is not returning full String

  24. 24

    Function returning pointer to string

  25. 25

    Compiling string and returning it as a vector

  26. 26

    String method returning null

  27. 27

    swift function not returning string?

  28. 28

    Why the function is not returning the string?

  29. 29

    Method not returning a string

HotTag

Archive