-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab3.py
137 lines (111 loc) · 2.17 KB
/
lab3.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
"""lab3
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ot9gYXWbXtsIJ2R2Ds8fZjI4qUSqBoi-
1. Write a Python program to find those numbers which
are divisible by 7 and multiple of 5, between 7and
270 (both included)
"""
l=[]
for x in range(7, 270):
if (x%7==0) and (x%5==0):
l.append(str(x))
print (l)
"""2. Write a Python program to count the number of even
and odd numbers from a series of numbers ex(1,5)
Input last number of series: 5
Output odd: 3
Output even: 2
"""
#numbers = [1, 2, 3, 4, 5]
count_odd = 0
count_even = 0
for x in numbers:
if not x % 2:
count_even+=1
else:
count_odd+=1
print(count_even)
print(count_odd)
"""3. Write a Python program to display numbers from (-10
,0)
"""
i = -10
while(i<=0):
print(i)
i += 1
"""4. Write a Python program to find factorial any number
Input: 4
Output: 24
"""
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n=int(input(" "))
print(factorial(n))
"""5. Write a Python program to find cube of range of
numbers ex :6 find cube to each number from 1 to 6
"""
num = int(input(" "))
cb = num*num*num
print(cb)
"""6. Given a number N. Print N lines that describes iti
game.
Input N: 3
Output
1 2 3 iti
5 6 7 iti
9 10 11 iti
"""
n = int(input(" "))
for i in range(1,4*n+1):
if i%4==0:
print("iti\n")
else:
print(i)
"""7. Write a Python program to count the sum of digits in
a number
Input:123
Output:
"""
n = int(input(" "))
count = 0
while(n > 0):
a = n % 10
count=count + a
n = n // 10
print(count)
"""8. Write a Python program to reverse any number
Input: 123
Output: 321
"""
n = int(input(" "))
rev = 0
while(n > 0):
a = n % 10
rev = rev * 10 + a
n = n // 10
print(rev)
"""
10. Write a program to check an integer is a palindrome
or not. An integer is a palindrome when it reads the same
forward as backward
Input: 123
Output: no
Input: 111
Output: ye
"""
num=int(input(" "))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("yes")
else:
print("No")