- 1

Sequence numbering Python 3

If i wamt to output 1. 2. 3. But don't want to keep writing each number..os there a way to make it faster ?

2nd Jul 2021, 6:49 PM
Amer
Amer - avatar
13 Antworten
+ 6
Amer , range can take 3 arguments: range(<start number>, <end number ( not including )>, <step>) see what this code is resulting: for num in range(5, 11): print(num) ''' result is: 5 6 7 8 9 10 '''
2nd Jul 2021, 8:16 PM
Lothar
Lothar - avatar
+ 4
if u use a wild range of numbers for n in [1,4,7,9,74]: print(f"{n}. ")
3rd Jul 2021, 5:08 AM
Oma Falk
Oma Falk - avatar
+ 3
for n in range (x): print(n) ---- This will print all integers from 0 to x.
2nd Jul 2021, 7:26 PM
Simon Sauter
Simon Sauter - avatar
+ 3
.... Simons solution but print(f"{n}.")
2nd Jul 2021, 7:39 PM
Oma Falk
Oma Falk - avatar
+ 3
for n in range(5, 11): if n != 7: print(n)
2nd Jul 2021, 9:48 PM
Simon Sauter
Simon Sauter - avatar
+ 2
Amer , i don't know what language you are going to, but you ca do it with a loop. you may need to get an input to define the max number to output. the numbers itself can be generated by a range or with a variable that will be incremented in each loop iteration. the dot after the number can be added during print output. happy coding and good success!
2nd Jul 2021, 6:58 PM
Lothar
Lothar - avatar
+ 2
Thanks guys it worked. One more thing Say i want to exclude 0..or make the range from 5 to 15 for example. How would it go.
2nd Jul 2021, 8:02 PM
Amer
Amer - avatar
+ 2
Amer it works! Oma Falk just forgot the colon at the end of the first line ...
3rd Jul 2021, 6:08 AM
Crash
Crash - avatar
+ 1
I'm learning python 3 Could you please assist me with an example ?
2nd Jul 2021, 7:06 PM
Amer
Amer - avatar
+ 1
Perfect. Say i want to exclude 7 from that range you resulted. So 5 6 8 9 10 Last question i swear 😆
2nd Jul 2021, 8:32 PM
Amer
Amer - avatar
0
Thanks alot guys
3rd Jul 2021, 5:05 AM
Amer
Amer - avatar
0
This one gave error
3rd Jul 2021, 5:30 AM
Amer
Amer - avatar
0
Works..thanks folks!
3rd Jul 2021, 8:04 AM
Amer
Amer - avatar