I tried to program to output this:
Write something: What? What? Write something: Fight the power. Fight the power. Write something: quit Bye bye!
but there's some problem with my code
i = input("Write something:")
while i != "quit":
print(i)
if i == "quit":
print("Bye bye!")
break
It says I have a syntax error Edit It was my fault for forgetting the parentheses but I added in and it says that my program doesn't operate correctly. I'm using an academic online console
Result of while loop in your code getting infinite loop in case if input is other than 'quit', may be due to this you are getting program doesn't operate correctly message. You can consider below code:-
i = input("Write something:")
while True:
if i != "quit":
print(i)
i = input("Write something:")
elif i == "quit":
print("Bye bye!")
break
You need to put ()
around your print
in your if statement.
Well, hi. You can look at the error you had and line. Problem is that your print
method has no parenthesis. Either, if it's python 2.7
, then there is a problem in print(i)
input()
evaluates the user input. You want:
i = raw_input("Write something:")
instead
You have to use round brackets for print function. If you have copy pasted program from somewhere, may be because of that this error. Type again program on your own and then run.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.