+ 1

what code is needed to separate the enter key from all other inputs?

im working on a code where i want to make it where if the user hits enter rather then the input asked for it comments for that and says a separate comment for the input asked for. Please someone help. i am coding im python 3. In the code there is one input with 2 different statements. when the code asks for the input if you only hit enter to proceed with the rest of the code i am wanting it to print one statement then loop back to the input but if you do type the input asked for, it responds with the 2nd statement.

15th Jun 2018, 12:46 AM
Arketa
Arketa - avatar
15 Respostas
+ 2
have you tried just checking if the input is blank? name=input("Enter Name: ") If name="": print("You entered Nothing") If name="Arketa": print("Hello {}".format(name))
15th Jun 2018, 1:05 AM
LordHill
LordHill - avatar
+ 1
thank you i will try that
15th Jun 2018, 1:07 AM
Arketa
Arketa - avatar
+ 1
I guess I don't understand what you want. sorry
15th Jun 2018, 1:20 AM
LordHill
LordHill - avatar
+ 1
in the code there is one input with 2 different statements. when the code asks for the input if you only hit enter to proceed with the rest of the code i am wanting it to print one statement then loop back to the input but if you do type the input asked for, it responds with the 2nd statement
15th Jun 2018, 1:33 AM
Arketa
Arketa - avatar
+ 1
I think your question is understandable!! here is my guess, while True: name=raw_input("Enter your Name: ") if len(name)<=0: print("Name should not be blank!") else: print("Your Name is: ",name) break
15th Jun 2018, 2:26 AM
Hemath Kumar
Hemath Kumar - avatar
+ 1
ok thank you we will look into that and see if either work
15th Jun 2018, 2:30 AM
Arketa
Arketa - avatar
+ 1
ok thank you we will we just started learning
15th Jun 2018, 2:32 AM
Arketa
Arketa - avatar
+ 1
i want to thank Forge brain your code worked for what we asked origanally
15th Jun 2018, 4:03 AM
Arketa
Arketa - avatar
+ 1
#This may help: def input_holder(): while True: try: yield input() except: break data = list( input_holder() ) print(data) #In sololearn or other IDE that take inputs from a file, the while loop will break due to an EOFError. #In other IDEs, you can use KeyboardInterrupt (ctrl+c) to end the while loop after you finish typing all of the inputs.
15th Jun 2018, 5:18 AM
æŽç«‹ćš
0
the way the code is you have to input something... whether it be enter or the input asked for.
15th Jun 2018, 1:11 AM
Arketa
Arketa - avatar
0
My another guessing about your question, You need user input for many lines, and you need to separate each input with enter! for this you may need, "fileinput" module
15th Jun 2018, 2:28 AM
Hemath Kumar
Hemath Kumar - avatar
0
ask if any doubt persists
15th Jun 2018, 2:31 AM
Hemath Kumar
Hemath Kumar - avatar
0
i also want to thank Hemath Kumar the code yougave us worked with the loop and the rest of the question however we didnt get a chance to test the fileinput yet.
15th Jun 2018, 4:05 AM
Arketa
Arketa - avatar
0
thank you both very much you both were very helpful
15th Jun 2018, 4:07 AM
Arketa
Arketa - avatar
0
thank you everything is helpful everything will be looked into
15th Jun 2018, 5:27 AM
Arketa
Arketa - avatar