I want to make a triangle of the character string on the right side by inputting the character string and the number of columns in Python.
The input character strings are arranged from left to right in the bottom row, and if it is cut off in the middle, the continuation of the character string is output in the upper row, and it feels like it is repeated up to the top row.
Output: Figure below
After trying various things, I happened to write a code like this. However, in this case, if the character string is cut off in the middle and goes to the upper row, it will be reset (?), So how can I continue it? (I'm sorry if I made a mistake from the ground up.)
word = str (input ("Enter the word:")) height = int (input ("Enter the height:")) for x in range (len (word)): word + = word for i in range (1, height + 1): for j in range (1, height + 1): if (j<= height --i): print ('', end ='') else: else: print (word [height + j], end =''') print ("")
Supplementary information (FW/tool version, etc.)
Please provide more detailed information here.
Answer # 1
word = str (input ("Enter the word:")) height = int (input ("Enter the height:")) TOTAL_LEN = height * (height + 1) // 2 WORD_LEN = len (word) word * = (height // len (word)) + 1 padding = "" * height for y in range (1, height + 1): pos = (TOTAL_LEN --y * (y + 1) // 2)% WORD_LEN print (padding [y:] + word [pos: pos + y])
Answer # 2
word = str (input ("Enter the word:")) height = int (input ("Enter the height:")) wordlength = sum ([i for i in range (height)]) word = word * (wordlength // len (word) + 2) s = 0 for i in range (height): print ('''* (height --i + 1), end ='') print (word [s: s + i + 1]) s = s + i + 1
Enter the word: python Enter the height: 12 p yt hon pyth onpyt honpyt honpyth onpython pythonpyt honpythonp ythonpython pythonpython
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory