+ 1

while Loop

>>> numbers=list(range(2,20,2)) >>> print(numbers) [2, 4, 6, 8, 10, 12, 14, 16, 18] How can i print ! with every number from above list. need following result: 2! 4! 6! 8! so on

23rd Aug 2017, 11:20 AM
Rohit Sajwan
6 odpowiedzi
+ 5
Or you can do what David did but do: print(i,end="!\n")
23rd Aug 2017, 12:59 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
for i in numbers: print(str(i) + '!')
23rd Aug 2017, 11:31 AM
David Katz
+ 1
Thanks David...got it. >>> x=0 >>> while x<=max_index: z=numbers[x] print(str(z)+"!") x=x+1 2! 4! 6! 8! 10! 12! 14! 16! 18! >>>
23rd Aug 2017, 10:40 PM
Rohit Sajwan
+ 1
x += 1 It's cleaner code
24th Aug 2017, 4:11 AM
David Katz
+ 1
x += 1 instead of x = x + 1
24th Aug 2017, 9:22 AM
David Katz
0
What so you mean by cleaner code?
24th Aug 2017, 8:57 AM
Rohit Sajwan