Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Better Coding
#1
import sys
rows=colcnt=11
dotcnt=center=(rows-1)
for cnt in range(1,(rows+1)):
  print("".ljust(dotcnt,'.'),end='')
  for c in range(dotcnt,colcnt):
    print ((cnt%10),end='')
    cnt=cnt+1 if(c < center) else cnt-1
  print ()
  dotcnt-=1
  colcnt+=1
Output:
..........1 .........232 ........34543 .......4567654 ......567898765 .....67890109876 ....7890123210987 ...890123454321098 ..90123456765432109 .0123456789876543210 123456789010987654321
Please help me to make this code more than what i wrote, thanks
For example , below code , i want to make print() comes inside the for loop , which i am not able to , please help
  for c in range(dotcnt,colcnt):
    print ((cnt%10),end='')
    cnt=cnt+1 if(c < center) else cnt-1
  print ()
Reply
#2
(Jul-30-2019, 01:43 PM)aankrose Wrote: Please help me to make this code more than what i wrote, thanks

What does 'more' mean?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(Jul-30-2019, 01:43 PM)aankrose Wrote: Please help me to make this code more than what i wrote, thanks
For example , below code , i want to make print() comes inside the for loop , which i am not able to , please help
To me, it seems that you don't know how to use a for loop. You want to use a for loop so you can make it more your code rather than using code someone else wrote. If you want to learn how to use a for loop, there's a tutorial here - https://python-forum.io/Thread-Tutorial-...-for-loops - otherwise I don't know what you're trying to say.
Reply
#4
(Jul-30-2019, 03:46 PM)perfringo Wrote:
(Jul-30-2019, 01:43 PM)aankrose Wrote: Please help me to make this code more than what i wrote, thanks

What does 'more' mean?

[/quote]
Hello perfringo

What i meant was , on my code , i have made print() in separate line, is there a way i can remove print() and use sep='/n' in print ((cnt%10),end='') to make my code look even better ?

[/quote]

for c in range(dotcnt,colcnt):
  print ((cnt%10),end='')
  cnt=cnt+1 if(c < center) else cnt-1
print ()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020