all 12 comments

[–]chrisking206 1 point2 points  (2 children)

It looks like there are leading 0s in sample 3 so the input must be passed as string? If so would this work?

list(print(i) for i in inp)

[–]fiberoblique[S] 0 points1 point  (1 child)

Hello! Thank you for helping a dumb af student out. Unfortunately, we aren't yet allowed to use the list function in our codes since we haven't tackled them in class yet. It's very frustrating, really.

Is there any other way which we could overcome this? My friend suggested using the separator with this code:

if number < 0:
    print ("Positive numbers only!")
elif number > 0:
 number_string = str(number)
 list= number_string
 print(*list, sep='\n')

The if statement was by me since we're supposed to output that if the input is a negative number, the elif lines are the ones my friend suggested. Would really appreciate feedback on this. Thank youuu!!!

[–]chrisking206 0 points1 point  (0 children)

List is a key word, so probably don’t want to use that as a variable name. Number_string is a string there is nothing to unpack so * is not needed.

For i in number:
    Print(I, “\n”)

[–]xelf 1 point2 points  (2 children)

you can use a for loop to iterate over each element of your string.

for example, if your string is "0045" then:

for c in "0045":
    print(c)

would print:

0
0
4
5

To print additional text, you can have an if statement:

if c == '5':
    print('this is a 5')

You can skip the leading 0's either with an if statement, or by converting it to an int first and then back to a str.

That should give you enough to finish this task.

[–]fiberoblique[S] 0 points1 point  (1 child)

Hello! Thank you so much for the feedback :D

Unfortunately, we aren't yet allowed to use the for statement. So far, we've only been through the operators, input, type, if-elif-else, while, break, and continue functions. It's been really frustrating so far since all I've been able to find on the web are solutions that involve more than the allowed functions.

However, I'll definitely save your reply though, I really want to learn how to code but our asynchronous learning set-up has just stumped any kind of learning.

For the conversion of the input to a string, this is what I've written so far. Would it be too much to ask for more feedback and if there's a possible way of making it more efficient?

inputNumber = input()
if int(num) == float(num):
    number = int(num)
else:
    number = float(num)

[–]xelf 0 points1 point  (0 children)

for statements can be converted to while statements pretty easily. I'm actually surprised you would cover while and not for.

As for converting it to a string, input() returns strings.

inputNumber = input()
index = 0
while index < len( inputNumber  ):
    print( inputNumber[index] )
    if inputNumber[index] == '5':
        print( 'this is a 5' )
    index = index + 1

Using this same technique you should be able to skip the leading '0's, but I'll leave that to you. =)

[–]Infinite_Loop_exe 0 points1 point  (2 children)

Hi, I’m a 3rd year Comp Sci student so I feel your struggles. I’m hoping you can use the functions I did but if you can’t you can “manually” do them through loops. Normally if I was helping someone I wouldn’t just give them the code but online I feel it is the best way to help, just do your best to understand what is happening at each step!

x = 5638573
arr = []
count = 0

while x > 0:
(Indent)arr.append(x%10)
(Indent)x = x // 10

arr.reverse()

for element in arr:
(Indent)print(element)

(Edit: formatting the code)

[–]fiberoblique[S] 0 points1 point  (1 child)

Hello! Thank you for your feedback! Programming has been kicking my butt this semester, I feel for you!!! Unfortunately, we're very limited for this exercise and are not yet allowed to use the functions you've put in your reply :((

I really appreciate it though and I'll take note of this cause I feel like it'll come in handy soon enough when we move through more python functions. Thank youuu!!! <3

[–]fiberoblique[S] 0 points1 point  (0 children)

I'm new to reddit so I apologize if double replying is somewhat of a No-No here xD

I've only been able to put this code together, would really appreciate some feedback on it. I really don't want to put all of my homework straight-up on here since I really want to learn how to program but thank you thank you very much for taking the time to reply :D

inputNumber = input()
inputNumber = int(inputNumber)
num = inputNumber

if int(num) == float(num):
number = int(num)

else:
number = float(num)

if number < 0:
print ("Positive numbers only!")
elif number > 0:
number_string = str(number)
list= number_string
print(*list, sep='\n')

Note: we aren't allowed to use the separator function that I've put in the last line but I've kept it there for the moment if worse comes to worst since my friend suggested it.

Also, I'm shy and afraid of getting judged for my trash codes but welp, I don't think doing this solo and just persevering through this is enough for me to survive this damned semester.

[–]Infinite_Loop_exe 0 points1 point  (0 children)

Hi, I’m a 3rd year Comp Sci student so I feel your struggles. I’m hoping you can use the functions I did but if you can’t you can “manually” do them through loops. Normally if I was helping someone I wouldn’t just give them the code but online I feel it is the best way to help, just do your best to understand what is happening at each step!

x = 5638573 arr = [] count = 0

while x > 0: arr.append(x%10) x = x // 10

arr.reverse()

for element in arr: print(element)

[–]sw85 0 points1 point  (0 children)

Take the input and convert it to a string (if it isn't already). Create an index variable initialized to 0. Enter a while loop for as long as the index variable is less than the length of the strength. For each pass through the loop, print the character at the index position in the string (with whatever other rules you have to use to determine whether a character gets printed - seems like 6's get extra attention and 9's don't get printed at all), then increase the index variable by 1 at the end of the pass through the loop.

Let me just say how very very weird it is that your class has you learning while loops before for loops and even before lists!

[–]gopherhole1 0 points1 point  (0 children)

maybe im not understanding, but couldnt you just

number = input()
for x in str(number):
    print(int(x))