Python Forum
Using If Statements Instead of While Loop in Simple Game Program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using If Statements Instead of While Loop in Simple Game Program
#6
Also, you have asked for input("") several times. You did not just get the input and store it.
input = ("")
if input("").lower() == "help":
     print("start - to start the car")
     print("stop - to stop the car")
     print("quit - to quit")
if input("").lower() != "help"
     print("Sorry, I don't understand that")
if input("").lower() == "start":
     print("Car started...")
if input("").lower() == "stop":
     print("Car stopped.")
if input("").lower() == "quit":
     break
What this says is, without giving a prompt, read a string from the console. Then, discard this string and read another string from the console. If this is equal to the word "help", print out the help message. Then ask for another input string. If this is not equal to "help" (even if it is "start", "stop" or "quit"), say that you don't understand it. Then, get another string. If this third input is "start", start the car, then read another string from the console. If this is "stop", stop; iif it is "bugsbunny", ignore it without issuing any warning message, then read another string from the console. If this is "quit" then quit; otherwise do nothing.

Since there is no loop, the program always terminates, unless you type "quit", in which case it should complain that there is no loop for the break statement. Overall, a terrible piece of code. It does not follow the specification of what it should do. It keeps asking for strings.
Reply


Messages In This Thread
RE: Using If Statements Instead of While Loop in Simple Game Program - by supuflounder - Dec-14-2021, 12:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  quiz game - problem with loading statements from file lapiduch 2 1,152 Apr-20-2023, 06:13 PM
Last Post: deanhystad
  How to compile following python loop program reinispl 3 2,035 Oct-27-2021, 01:57 PM
Last Post: DeaD_EyE
  RockPaperScissor program while loop malfunction tonyliang19 3 2,948 Apr-03-2020, 11:09 PM
Last Post: SheeppOSU
  Simple maze game controls OmegaSupreme 4 4,168 Apr-26-2019, 08:55 AM
Last Post: OmegaSupreme
  Program that, inside a loop, does multiple things. needs to print in a certain way reidmcleod 1 2,738 Feb-19-2019, 02:35 PM
Last Post: marienbad
  How to hold a program in the turtle (Tic-Tac-Toe game assignment) kmchap 1 4,653 May-17-2018, 05:39 PM
Last Post: j.crater
  Supposedly simple program not working! Please help! BenjaminDJ 5 4,163 Feb-20-2018, 08:43 PM
Last Post: BenjaminDJ
  Simple Python program not working AudioKev 3 3,305 Jan-23-2018, 09:57 PM
Last Post: Larz60+
  help with while loop on dice game sean5 2 4,273 Dec-14-2017, 07:24 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020