+ 2
Taking input multiple times in solo learn. How to make this shorter
https://code.sololearn.com/cBObh8gBKkR8/?ref=app My program checks if the password you have selected is valid if not it requires you to input password again. In a separate ide I was using a while loop but the input method is not being recognized in solo learn how can I get around this Another question is how can I make this shorter. I am new to python so I usually end up writing longer code when there is a shorter way of doing it
13 Antworten
+ 7
Sololearn input is not interactive. It needs all required inputs at once before start execution. So just enter all inputs by line by line separated in the pop-up then hit enter.
Ex:
ABC <press enter>
Abcde <press enter>
Abc1 <press hit>
You can use letter.isdigit() method to check if it is digit or not. So no need list of numbers and no need inner loop.. You can return true then just. Otherwise return false, can be reduce furthermore...
+ 10
Sami Yemane ,
this is an approach that uses a for loop and the string method isdigit(). it does not need a counter, since we will break in case of a digit is detected when iterating on the input string. then return value is True.
if there is no digit detected, the loop will terminate, but by using an else clause. then return value is False.
you should adapt your main program to get the return value, and then select the respective output.
def seperator(word):
for char in word:
if char.isdigit():
return True
else:
return False
... call of function ...
+ 4
Furthermore you could use the so-called "comprehensions" to reduce the whole loop to a oneliner:
while True:
if any(letter.isdigit() for letter in password):
break
+ 3
For Python codes on Sololearn, it's easiest to refrain from using infinite loops and just reduce it to a single input.
It may not be the best or realistic way, but that's just the way it is here with console-based codes.
So basically like:
x = input()
if x == whatever:
print('Yay!')
else:
print('Nay.')
+ 1
HonFu that is an interesting solution I will try it out
+ 1
Jayakrishna🇮🇳 thanks that sucks tho for what I am trying to do
Does the isdigit() return true if the argument is an int
+ 1
Thanks guys I have just tried it I get what it does now
+ 1
Sami Yemane, isdigit is a method of the string datatype, so it works directly on the string (your input) and doesn't need a conversion to int.
+ 1
HonFu thanks
+ 1
print("012345789".isdigit()) # true
print("abc1".isdigit()) #false
# isdigit() method of str class returns true, if the all characters are digits in string else false.
+ 1
Jayakrishna🇮🇳
Thanks got it
0
Lothar does the isdigit only work of the input is a int because I tried getting the type and it was a string
0
Sami Yemane for continuous input, you can use loop. For eg.-
i=0
while i<10:
password_input=input()
And if you want to match password:
use re module
import re
pattern=r"[0-9]+