Tinywow - PYTHON PROGRAMS - 9391724
Tinywow - PYTHON PROGRAMS - 9391724
output :-
Enter First number : 25
Enter Second number : 87
Enter Third number : 40
The largest of the 3 numbers ‘is : 87
The smallest of the 3 numbers ‘is : 25
Pattern 1 :-
for i in range(1,6):
for j in range(65,65+i):
a = chr(j)
print(a, end=" ")
print("\r")
5. Generate the following patterns using nested
loop.
Pattern 1 :-
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s = 0
for a in range (n + 1) :
if a%==0
s+= x**a
else
s-= x**a
print ("Sum of series", s)
Pattern 2 :-
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s = 0
for a in range (n + 1) :
if a%2==0:
s+= x**a
else:
s -= x**a
print ("Sum of series", s)
Pattern 3 :-
x = float (input ("Enter value of x :"))
n = int (input ("Enter value of n :"))
s = 0
for a in range (n + 1) :
if a%2==0:
s += x**a
else:
s -= x**a
print ("Sum of series", s)
Pattern 4 :-
def palindrome(n):
temp = n
rev = 0
while n > 0:
dig = n % 10
rev = rev * 10 + dig
n = n // 10
if temp == rev:
print(temp, "The number is a palindrome!")
else:
print(temp, "The number isn't a palindrome!")
def armstrong(n):
count = 0
temp = n
while temp > 0:
digit = temp % 10
count += digit ** 3
temp //= 10
if n == count:
print(n, "is an Armstrong number")
else:
print(n, "is not an Armstrong number")
def perfect(n):
count = 0
for i in range(1, n):
if n % i == 0:
count = count + i
if count == n:
print(n, "The number is a Perfect number!")
else:
print(n, "The number is not a Perfect
number!")
if __name__ == '__main__':
n = int(input("Enter number:"))
palindrome(n)
armstrong(n)
Output:-
7. Input a number and check if the number is a
prime or composite number.
if num > 1:
if (num % i) == 0:
break
else:
elif num == 0 or 1:
else:
output :-
Enter any number : 1
1 is a neither prime nor composite number
8. Display the terms of a Fibonacci series.
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
print("The L.C.M. is", compute_lcm(num1, num2))
Output :-
Enter 1st: number: 3
Enter 2nd number: 5
char ch = str[i];
// Driver function.
int main()
{string str = "geeks for geeks121";
countCharacterType(str);
return 0;}
Output:-
Vowels = 5
Consonant = 8
Digit = 3
Special characters = 2
11. Input a string and determine whether it is a
palindrome or not; convert the case of characters
in a string.
my_str = 'aIbohPhoBiA'
Output :-
The string is a palindrome.
12. Find the largest/smallest number in a
list/tuple.
lst = []
num = int(input('How many numbers: '))for n in
range(num):
numbers = int(input('Enter number '))
lst.append(numbers)print("Maximum element in the
list is :", max(lst), "\nMinimum element in the list
is :", min(lst))
Output:-
13. Input a list of numbers and swap elements at
the even location with the elements at the odd
location.
output:-
Output:-
Given list:
[('Mon', 3), ('Tue', 1), ('Mon', 2), ('Wed', 3)]
Check value:
Mon
The tuples satisfying the conditions:
[('Mon', 3), ('Mon', 2)]
15. Input a list of numbers and find the smallest
and largest number from the list.
# list of numbers
list1 = [10, 20, 4, 45, 99]
n=int(input("Enter n: "))
d={}
for i in range(n):
roll_no=int(input("Enter roll no: "))
name=input("Enter name: ")
marks=int(input("Enter marks: "))
d[roll_no]=[name,marks]
for k in d:
if(d[k][1]>75):
print(d[k][0])
Output:-
Enter n: 2
Enter name: a
Enter marks: 85
Enter name: b
Enter marks: 55