+ 3
How to print 100 times a word
16 Antworten
+ 9
Use for loop
+ 9
Vishal Tiwari ,
since python can multiply a string with an integer number, we can also use the print function with the string (to print) + a newline sequence, multiplied by the requested number.
+ 6
Vishal Tiwari
A quick and easy way is to use the repeat function from the itertools
from itertools import repeat
# defining number of times to repeat
n = int(input())
# define the word or words to be printed
w = input() or "Word" print(list(repeat(w, n)))
+ 4
Learn programming
+ 4
Python :
for i in range(100):
print("hello")
Java :
public class HelloWorld {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
System.out.println("hello");
}
}
}
C:
#include <stdio.h>
int main() {
for (int i = 0; i < 100; i++) {
printf("hello\n");
}
return 0;
}
C++ :
#include <iostream>
int main() {
for (int i = 0; i < 100; i++) {
std::cout << "hello" << std::endl;
}
return 0;
}
Kotlin :
fun main() {
repeat(100) {
println("hello")
}
}
JavaScript :
for (let i = 0; i < 100; i++) {
console.log("hello");
}
Ruby :
100.times do
puts "hello"
end
These are some examples of print "hello" 100 times, .there are some ways are present to print it
+ 4
In python
for i in range(100):
print("hello")
+ 3
Welcome to SoloLearn
Printing 100 times a word is one of the first things you will learn in any basic programming course.
Hint: loops
Keep learning and you'll get there.
If you need help with a specific programming language you should make that clear in the question tags.
+ 2
Use for loop by giving range
+ 1
Vishal Tiwari You could just say
print(“Hello” * 100) and that would print it 100 times
and if you want to print it all on new lines you can use the new line character
print(“Hello\n” * 100)
+ 1
In python just to write
For i in range(100):
Print(word)
Word will printed 100 times
+ 1
For many languages I'll propose use of a loop because it's short and easy.
0
Use for loop
for i in range(100):
print("Your message")
0
#include <iostream>
int main() {
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word\n";
std::cout<<"word";}
0
Fukari Floryda What if i wanted to print world\n 10k times?
0
You can use loop to do that, while or for loop