How do i print out a number triangle in python? [closed]
2024/11/24 22:36:18
How do i print out a number triangle in python using a loop based program? It is not a homework assignment or anything its just an exercise from the book i have been trying to do but have not really come close. The triangle should print out looking like this:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
Answer
Just thought I would drop this here, even though it actually avoids using nested loops. But uses some elegant algebra.
for i in range(1, n):print((i*(10**i-1))//9)
In essence it is simply because 10^n-1 is n consecutive 9s. I will leave the rest up to you ;-)
I want to create real time clock using Tkinter and time library. I have created a class but somehow I am not able to figure out my problem.My codefrom tkinter import *import timeroot = Tk()class Clock:…
i am trying to convert my python code to dll using cffi so i can access this code in my c# apllication, and i am trying to send image my c# code to python function, below is my code to read the file an…
I have installed Python 3.6.5 however when i type Python it shows Python 2.7.5.
Id like to use Python 3.[aravind@aravind05 Python-3.6.5]$ python3 --version
Python 3.6.5[aravind@aravind05 Python-3.6.5]$…
Id like to write a program in Python where user define a deegre of polynomial and coefficients (a,b,c). When program create a polynomial expression with this data Id like to use it like function becaus…
This question already has an answer here:Using sublists to create new lists where numbers dont repeat(1 answer)Closed 9 years ago.Given thatg=[[1,2,3,4],[4,5,6],[6,7],[10,11]]What code should I use to …
This question already has an answer here:Compiler error "error: stray \ in program" in macro definition(1 answer)Closed 10 years ago.The following python codeenv.Command(versionFile, allSrcs …
I am using Selenium to enter data on a web page, but have run into an issue with one of the input fields. This is the HTML code causing my difficulty:<div class="form-group">
<label …
I want to list all of my disk and can be able to know its type: "SATA" "NVME" "M.2" or "PCI" on Windows computer.
I made some research with wmi and I get the int…
I work on pose estimation of a 3d objects. I am using CAD model of that object to generate all the possible hypothesis of its pose.
I am using pyopengl to render the view of the object from a specific…
The following program simulates a traffic light system with some buttons. The buttons appear correctly, but if Im trying to call the method to create/change the LEDs, it ends up in the wrong method. He…