26
loading...
This website collects cookies to deliver better user experience
for i in range (0,k):
#statement
#the statement will run k times
>>> for i in range (0,5) #don't forget the semicolon
File "<stdin>", line 1
for i in range (0,5)
^
SyntaxError: invalid syntax
>>> for i in range (0,5):
... print("hello") #don't forget the indent
File "<stdin>", line 2
print("hello")
^
IndentationError: expected an indented block
>>> for i in range (0,5):
... print("hello")
...
hello
hello
hello
hello
hello
>>> for i in range (0,5):
... i=0
... print("hi")
...
hi
hi
hi
hi
hi
>>> for i in range (0,10,2): #here 2 represents the increment values.
... print(i)
...
0
2
4
6
8
n=int(input("Enter a number"))
for i in range (0,n):
if n%i==0:
print(i)
#Program to find the factorial of a number
a=int(input("Enter a number "))
for i in range (1,a):
a=a*i
print(a)
break
continue
a=int(input("Enter a number "))
IsPrime=0
for i in range (2,a//2):
if (a%i==0):
print("The number is composite ")
IsPrime=1
break
if (IsPrime==0):
print("The number is prime.")