-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_04forloop.py
More file actions
104 lines (68 loc) · 1.71 KB
/
Copy pathday_04forloop.py
File metadata and controls
104 lines (68 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#---------------------------------------
#day4_forloop
#---------------------------------------
#1.print numbers from 1 to 100
for i in range(1,101,1):
print("Numbers from 1 to 100:",i)
print("-----------------------------")
#2.sum of N numbers
n=int(input("Enter n:"))
sum_n=n*(n+1)//2
print("The sum of N numbers:",sum_n)
n=int(input("Enter n:"))
sum_n=0
for i in range(1,n+1):
sum_n += i
print("Sum of N numbers:",sum_n)
print("------------------------------")
#3.print even numbers from 2 to 20
for i in range(2,22,2):
print("even numbers from 2 to 20:",i)
print("-----------------------------")
#4.print all the letters in your name
name=str(input("Enter name:"))
for n in name:
print("letters=",n)
print("----------------------------")
#5.factorial of a number
n=int(input("Enter a number:"))
fact=1
for i in range(1,n+1):
fact*=i
print("Factorial of a given number %d is %d",%(n,fact))
print("-----------------------------")
#6.Fibonacci Series
terms=int(input("Enter number of terms:"))
print("Fibonacci Series")
a,b=0,1
print(a,b,end=" ")
for i in range(terms):
c=a+b
print(c,end=" ")
a=b
b=c
print ("-------------------------------")
#7.Armstrongnumber
print("Armstrong number demo")
num=int(input("Enter number:"))
n=num
digits=len(str(num))
sum=0
while n>0:
digit=n%10
sum=sum+digit**digits
n=n//10
if(sum == num):
print("Yes It is an Armstrong number.")
else:
print("Its not an Armstrong number.")
print("------------------------------")
#8.Primecheck
n=int(input("Enter number:"))
for i in range(2,n+1):
if(n%i==0):
print("It is not a prime number")
break
else:
print("It is prime number")
print("----------------------------")