0% found this document useful (0 votes)
7 views

For Loop Assignment

random python codes for beginners

Uploaded by

fariapers07
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

For Loop Assignment

random python codes for beginners

Uploaded by

fariapers07
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#reverse a number using for loop

"""
num=int(input("enter a number"))
reverse=" "
for i in range str(num):
val=num%10
reverse=reverse+str(val)
num=num//10
if num<=0:
break
print("the reversed number is",reverse)
"""

#fibonnaci using a for loop


"""
limit=int(input("enter nth number"))
num1=0
num2=1
print(num1,num2,end=" ")
for i in range(limit):
c=num1+num2
print(c,end=" ")
num1=num2
num2=c
"""
#largest num using a for loop
"""
num1=int(input("enter 1st number"))
num2=int(input("enter 2nd number"))
num3=int(input("enter 3rd number"))
for i in range(num1,num2,num3):
if num1>num2 and num1>num3:
print(num1,"is the largest which the first one")
elif num2>num1 and num2>num3:
print(num2,"is the largest which the second one",num2)
else:
print(num3,"is the largest which is third one")
"""
#code on prime numbers using for loop
"""
num=int(input("enter a number"))
for i in [2,3,5,7]:
if num%i==0 and num!=1:
print("its not a prime number")
break
else:
print("its not a prime number")
"""

You might also like