+ 1
I want to write Divyanshu 100 times in python
Please help
19 Respostas
+ 7
indent the last line,
this is the correct code:
name="Divyanshu"
for _ in range(100):
print (name)
+ 9
Menaal Anwar Fatima ,
before you ask for help, you should do a try by yourself first. please show your code here.
+ 3
Indentation is covered in the lesson, you can review the slides.
Here is a short explanation.
A for loop statement is a block statement. It consists of the "for i in range(10):", and the body which is following. And the body has to be indented.
For example:
for i in range(5):
print(i) # it will result in error because the body "print(i)" is not indented.
for i in range(5):
print(i) # it will print 0, 1, 2, 3, 4 on screen because the body "print(i)" is indented.
Normally we use 4 spaces for indentation, but SoloLearn use 2 spaces in their examples. It is most probably to fit the screen on mobile as more spaces will wrap the line, make it difficult to read.
+ 3
this place is not for getting readymade codes , here you can ask doubt and problems you faced while making a code or somthinge
+ 2
Thank you
+ 2
name = “Divyanshu”
print(name*100)
This will print the string 100 times becaus when you multiply a string, it just duplicates.
+ 1
There is an indentation error.
The body of the for loop is not indented.
+ 1
It's very simple add this code
string_to_print = "Divyanshu"
for _ in range(100):
print(string_to_print)
string to print is Targeted keywords
+ 1
Try this :
while True :
print ("Divyanshu")
0
Ohk
0
Didn't understand wong hei
0
As I am a beginner
I don't know much
0
🙂
0
for i in range(100):
print("Divyanshu")
0
It would help if it was Javascript, but it's python and I got stuck in the sequence too
0
You can use a simple loop in Python to achieve this. Here's an example code to print "Divyanshu" 100 times:for _ in range(100):
print("Divyanshu")This code will iterate 100 times and print "Divyanshu" in each iteration.
0
If you want to do same task again and again you can use loops for that task here you want to print Divyanshu 100 times and for that we can use any loop I will give you the code in for loop but if you are a biggner I suggest you should try it with every type of loop the code is below
for i in range(100):
Print("Divyanshu")
0
It will be print("Divyanshu"*100)