This Python program is designed to generate an Alphabet Rangoli of a given size. The size is determined by the user's input. The Rangoli is a form of Indian folk art which is drawn on the ground using materials such as colored rice, dry flour, colored sand or flower petals. In this case, the Rangoli is drawn using alphabets.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution works by first calculating the width of the Rangoli, which is determined by the formula (n - 1) * 2 + ((n * 2) - 1). The program then generates the upper half and the bottom half of the Rangoli separately. For each half, it calculates the number of letters to be printed in each line, and then generates the line by adding the appropriate letters and dashes. The letters are determined by their ASCII values, starting from 97 (which corresponds to 'a') and adding the input number minus 1. The ASCII value is then adjusted according to the position in the line.
n = int(input().strip())
w = (n - 1) * 2 + ((n * 2) - 1)
for i in range(1, n):
number_of_letter = (i * 2) - 1
s = ""
letter_value = 97 + n - 1
for i in range(number_of_letter):
if i != 0:
s += "-"
s += chr(letter_value)
if i < (number_of_letter - 1) / 2:
letter_value = letter_value - 1
else:
letter_value = letter_value + 1
print(s.center(w, "-"))
for i in range(n, 0, -1):
number_of_letter = (i * 2) - 1
s = ""
letter_value = 97 + n - 1
for i in range(number_of_letter):
if i != 0:
s += "-"
s += chr(letter_value)
if i < (number_of_letter - 1) / 2:
letter_value = letter_value - 1
else:
letter_value = letter_value + 1
print(s.center(w, "-"))
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.