0

Python. More elements than requested.

### try: DATA=list(func1()) corn=1 except: print("Step 3 skipped due to no integers") corn=0 if corn!=0: try: a, b=DATA print(a, b) pop=1 except: print("An integer is missing") pop=0 try: a=DATA print(a) ice=1 except: print("idk, but something is broken") ice=0 ### This is the last bit of code I had to cut down to fit on the forum. The idea is to request user input twice. The code detects if integers are used. If any integers are used, the info is returned to "def func1()". My issue is I'm getting too many elements in DATA than I requested. If I input one integer and one string, the end result should be a list with only one element (the integer). Instead, the list is created with as many elements as there are digits. Anyone have an idea as to how this is happening? I'm at a loss. Ill post code as public, as "slams_face_on_desk" if anyone is kind enough to offer some advice. https://code.sololearn.com/cTLzsEWQl6LF/#py @Diego tyvm. I believe I fixed the zero not being detected as an integer. But why return[one] or return[two]. Am curious, will try to figure it out. Thanks guys

18th Nov 2019, 9:08 PM
Joshua Cronin
Joshua Cronin - avatar
3 Answers
+ 3
You're returning strings from func1(), not integers. Variables "a" and "b" are strings, but "one" and "two" are their integers equivalents. print(list("123")) # ['1', '2', '3'] print(list(123)) # [123] 1. Change line 25 to return [one, two] 2. Change line 29 to return [one] 3. Change line 32 to return [two] 4. If the user inputs 0 your program will think it's not an integer (see lines 15, 19, 20, 23, 26). 5. It's better if you share the link of your code in the description of your question. https://code.sololearn.com/cTLzsEWQl6LF/?ref=app
18th Nov 2019, 9:56 PM
Diego
Diego - avatar
0
you could try something like a, b, *_ = DATA. and a, *_ = DATA for the second one. but without seeing the rest of the code, I cant see what your actually trying to do e.g, what does the func1() do.
18th Nov 2019, 9:54 PM
rodwynnejones
rodwynnejones - avatar
0
My apologies. Just posted the link to the page. But yea.
18th Nov 2019, 10:01 PM
Joshua Cronin
Joshua Cronin - avatar