Keen Learner and Exp... • 1d
Day 4 of learning python as a beginner. Topic: printing * pattern using while and for loop. I took the famous challenge of printing a * (star) pattern my goal was to print a triangle and diamond shape pattern. first I used int(input()) function to take input in an integer from the user then I used a for loop to create a loop which will print the pattern. As for loop excludes the last number therefor to avoid that I added row+1 this means that "add +1 to the user input" now for loop will include row (user's input). Then I have to add spaces from the margin in order to get a visually centered pattern (not the one which sticks to the left margin) and thus I used print(" " * (row-i), end ="") as I discovered, less stars = more spaces from the margin (typically in decreasing order like 4, 3, 2, 1) and thus row-i makes sure that the space is printed in decreasing order (ex- input 5 rows now row-i = 5-1=4 spaces printed (as loop stars from 1) ). end="" ensures that there is no new line entered by default. I used, print("*" * (2*i-1)) to print stars in odd numbers (1, 3, 5, etc). in line 25 I used, for i in range(row-1, 0, -1) here row-1 makes sure that the loop stars in descending order which will help in printing less spaces in first row and more spaces in last row (for diamond pattern). I didn't started loop with "row" only because I don't want to repeat the last line of triangle pattern (which is the middle line of diamond pattern) and -1 in the last emphasis that the printing starts backward (more stars first less stars in the end). I know I may have confused you a lot especially with my explaination fell free to ask any questions and suggest any alternative method so that I can improve the code. Also here's my code.
Crafting Impactful A... • 12d
🧠 Programming Challenge of the Day Can you solve this? You're given an integer array (with both positive and negative values). Each element in the array represents the number of stars (*) to be printed vertically in its column: 🔹 Positive values
See MoreBe confident • 10m
Name : Instant print **InstantPrint** is an on-demand document printing and delivery app designed for students. It allows users to upload documents, select print options (black & white or color, single or double-sided, paper size), and receive printe
See MoreAssistant Marketing ... • 4m
Working on project from past 1.5years, Online print biz. print in gifting, print in marketing posm, print for clg & scholl students. i know many companies are involved in this online industury. but i find some gap in quality. one whitespace i had fou
See MoreMy vision starts whe... • 3m
Looking for a Garment Printing Partner in Delhi We're seeking a Delhi-based garment printer who offers the following services at minimal pricing: DTF Printing Sublimation Printing Puff Printing Digital Printing If you or someone you know has t
See MoreDownload the medial app to read full posts, comements and news.