+ 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.
15 Antworten
+ 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))
+ 1
thank you i will try that
+ 1
I guess I don't understand what you want. sorry
+ 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
+ 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
+ 1
ok thank you we will look into that and see if either work
+ 1
ok thank you we will we just started learning
+ 1
i want to thank Forge brain your code worked for what we asked origanally
+ 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.
0
the way the code is you have to input something... whether it be enter or the input asked for.
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
0
ask if any doubt persists
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.
0
thank you both very much you both were very helpful
0
thank you everything is helpful everything will be looked into