python - Determining if a string is only digits using a function -


I have to type a function that will be true or false when the user will input based on these strings if it is all digits or not. This is what I still have, but I'm not sure what's wrong

  def string (): st = input (enter 'string:') if st.isdigit () : Stc = 'right' else: stc = 'False' return stc n = int (Input ("Number of runs:")) In the range (i): print () stc = string () If stc == ' True ': print (' True ') Other: Print (' False ')  

You should only return STC back to else

:

  def string (): st = input ('string enter:') if st .isdigit (): STC = 'True' else: stc = 'False' return stc  

But Booley Instead of using strings to represent the values ​​directly True and false ?

  def string (): st = input ('enter string') if st.isdigit (): stc = true else: stc = wrong return STC  

Then if you can change the conditi and everything will be a little good:

  ... stc = string () If stc: print ('True') else: print (' False ')  As mentioned in the comments, you can only leave the condition completely and only  st.isdigit ()  

update:

/ Code> By the way:

  def string (): st = input ('string enter:') return st.isdigit ()  

Keep in mind that now you get a boolean value ( True / False ) as a return, so you should optimize-if-condition

Will need

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -