How to know if a user has pressed the Enter key using Python

后端 未结 2 1462
失恋的感觉
失恋的感觉 2021-01-04 07:45

How to know if a user has pressed Enter using Python ?

For example :

user = raw_input(\"type in enter\")
if user == \"enter\":
    print \         


        
2条回答
  •  别那么骄傲
    2021-01-04 08:36

    user_input=input("ENTER SOME POSITIVE INTEGER : ")
    if((not user_input) or (int(user_input)<=0)):    
      print("ENTER SOME POSITIVE INTEGER GREATER THAN ZERO") #print some info
      import sys        #import
      sys.exit(0)       #exit program 
    '''
    #(not user_input) checks if user has pressed enter key without entering  
    # number.
    #(int(user_input)<=0) checks if user has entered any number less than or 
    #equal to zero.
    '''
    

提交回复
热议问题