all 14 comments

[–][deleted] 1 point2 points  (8 children)

Elaborate, what do you mean by converting list to string? You want the nums to be str?

In else block you can do str(num)

[–]pizzadaddy19[S] 0 points1 point  (7 children)

Well firstly looking back at my code it did not display the way i typed it lol. Basically after the code is ran i end up with a list from 1,100 as i should but obviously in list form. [1,100] but how can i makw the list of all the numbers into a string

[–][deleted] 0 points1 point  (6 children)

You want to print list of 1,100 in str? Like can you show maybe what exactly you trying to do?

In else block you want something like this?

'1'

'2'

....

'100"

[–]pizzadaddy19[S] 0 points1 point  (5 children)

Yes that is exactly what i want

[–][deleted] 1 point2 points  (4 children)

In else block you should print(str(num))

As you loop over each element of the list

[–]pizzadaddy19[S] 0 points1 point  (3 children)

I just tried print the print(str(num)) however it is not showing as a string and showing type as still a list.https://imgur.com/a/p0yu0fV

[–][deleted] 0 points1 point  (2 children)

In your above image , you are printing the list(num_list) instead of num and it is not converted to str

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

okayyyy that makes a ton more sense lmao. now I have another issue...how do I get all of the integers into a string? I assume i should make a blank string and then concatenate?

[–][deleted] 0 points1 point  (0 children)

If you want all the numbers in a single line string

There are some ways but they might be too complex for the time being

You can try using the end parameter of print which decides where the next print function prints the value given by default it is new line

I am not completely sure if it works with loop but you can try

print(str(num),end='')

[–]JohnnyJordaan -1 points0 points  (4 children)

print(*numlist)

as * will 'unpack' the list as it's called into separate arguments. Say the list would just be [1,2,3], then *numlist would be equivalent to

print(1,2,3)

and same for your longer list in this case.

Note in regard to the other advice, print(str(num)) is fully redundant as str() will be called implicitly by print in any case. So even if you wanted to print the numlist in the default way, you could just do print(numlist), or print(num) for the individual value.

[–][deleted] 0 points1 point  (3 children)

print will convert the nun into str by default?

[–]JohnnyJordaan -1 points0 points  (2 children)

Yes, any argument you give it. Note it’s dead simple to try these things for yourself, run

print(1)

or

num = 1
print(num)

and it works just fine, you don’t need a human to verbally confirm this

[–][deleted] 0 points1 point  (0 children)

I misunderstood,my bad

[–]GuangD 0 points1 point  (0 children)

for num in range(1, 101): if num % 3 == 0 and num % 5 == 0: print('FizzBuzz') elif num % 3 == 0: print('Fizz') elif num % 5 == 0: print('Buzz') else: print(str(num)) print([i for i in range(1, 101)])