RAI Program Assignment
RAI Program Assignment
Class- 10 I
roll no- 7
admission no-115102
Subject- RAI Program assignment
L.sort(reverse=True)
s=L[1]
if s is not None:
Output:
l=len(s)
print(l)
Output:
11
n1=int(input("enter number1\n"))
n2=int(input("enter number2\n"))
while n2!=0:
n1,n2=n2,n1%n2
print("GCD=",(n1),sep="")
Output:
>enter number1
54
>enter number2
24
GCD=6
s=input("enter ay string\n")
vowels="aeiouAEIOU"
c=0
for char in s:
if char in vowels:
c+=1
print("number of vowels",c)
output:
Hello world
Number of vowel is 3
s=0
while n>0:
digit=n%10
s+=digit
n//=10
print("sum of digits",s)
Output:
Sum of digits is 15
s2=s1[::-1]
if s1==s2:
print("paliindrome")
else:
print("Not Palindrome")
Output:
racecar
racecar is a palindrome
r=s[::-1]
print(r)
Output:
Akshat
tahska
if num>1:
for i in range(2,num):
if (num%i)==0:
break
else:
print(num,"PRIME NUMBER")
else:
Output:
11
11 prime number
factorial=1
for i in range(1,num+1):
factorial*=i
print("Factorial of",num,"is",factorial)
Output:
Factorial of 5 is 120
sum=0
for i in range(1,6):
sum+=i
OUTPUT:
s=s.isdigit()
print(s)
Output:
“123”
True
l=[1,2,3,4,5]
a=sum(l)/len(l)
print("average of list=",a,sep="")
Output:
>average of list=3.0
for x in range(1,n+1):
count=0
for y in range(1,x+1):
if x%y==0:
count+=1
if count==2:
print(x)
Output:
11
13
17
19
Q14-Wapp to check if two lists are identical (contain the elements in the same orde)r
list1=[1,2,3,4,5]
list2=[1,2,3,4,5]
print(list1==list2)
Output:
True
s="Hello, World!#$&*1234"
print(c)
Output:
HelloWorld1234
l=[1,2,3,4,5]
k=2
k=k%len(l)
r=l[-k:]+l[:-k]
print(r)
Output:
[4, 5, 1, 2, 3]
l=[1,23,4,4,55,5,9,9,10,10]
print(max(set(l),key=l.count))
Output:
l1=[1,2,3,4,5,6,7,8,9,10]
l2=[4,5,6,8]
c=list(set(l1)and set(l2))
print(c)
Output:
[8, 4, 5, 6]
list1 = [1, 2, 3, 4, 5]
list2 = [2, 3, 6, 7]
list3 = [0, 2, 3, 8]
intersection = set(list1)
result = list(intersection)
Output:
[9, 10, 4, 5]
if is_anagram:
else:
Output:
Q21-Wapp to remove duplicates from a list while maintaining the original order
lst = [1, 2, 3, 2, 4, 5, 1, 6, 5]
unique_lst = []
for item in lst:
unique_lst.append(item)
Output:
while num2 != 0:
Output:
Output:
Enter a number: 5
lst = [1, 2, 3, 4, 2, 5, 6, 3, 7, 8, 1]
duplicates = []
for i in range(len(lst)):
Output:
Output:
lst = ['a', 'b', 'c', 'e', 'i', 'o', 'u', 'd', 'f', 'g']
no_vowels = []
no_vowels.append(char)
sum_of_squares = 0
sum_of_squares += i ** 2
Output:
Enter a number: 20
squares = []
squares.append(num ** 2)
Output:
Q29-Write a Python program to find the sum of all even numbers in a list
Output:
single_string = ''.join(chars)
print("String:", single_string)
Output:
String: hello
Q31-Write a Python program to find the first non-repeated character in a given string
s = "swiss"
for char in s:
if s.count(char) == 1:
break
Output:
numbers = [3, 1, 4, 1, 5, 9, 2, 6]
smallest = min(numbers)
Output:
Smallest element in the list: 1
number = 121
num_str = str(number)
if num_str == num_str[::-1]:
else:
Output;
121 is a palindrome
numbers = [1, 2, 3, 4, 5]
reversed_list = numbers[::-1]
print("Reversed list:", reversed_list)
Output:
Reversed list: [5, 4, 3, 2, 1]
l1 = [1, 2, 3]
l2 = [3, 4, 5]
Output:
Q36-Write a Python program to check if a given string is a program (contains every letter of the alphabet
at least once).
import string
alphabet = set(string.ascii_lowercase)
print(f'"{s}" is a program')
else:
Output:
"The quick brown fox jumps over the lazy dog" is a program
s = "abc"
substrings = []
for i in range(len(s)):
substrings.append(s[i:j])
Output:
sentence = "the quick brown fox jumps over the lazy dog"
words = sentence.split()
sorted_words = sorted(words)
Output:
Sorted words: brown dog fox jumps lazy over quick the the
Q39Write a Python program to count the number of consonants and vowels in a given string.-
s = "Hello, World!"
vowels = "aeiouAEIOU"
Output:
Number of vowels: 3
Number of consonants: 7
Q40-Write a Python program to calculate the Least Common Multiple (LCM) of two numbers.
import math
num1=12
num2=15
print("Least Common Multiple (LCM) of", num1, "and", num2, "is:", l cm)
Output:
import math
number = 16
square_root = math.sqrt(number)
Output:
number = 28
if sum_of_divisors == number:
else:
Output:
28 is a perfect number
lower = 100
upper = 1000
armstrong_numbers = []
num_digits = len(str(num))
if sum_of_powers == num:
armstrong_numbers.append(num)
Output:
Q44-Write a Python program to find the length of a string without using the built-in len() function
s="Hello, World!"
count=0
for char in s:
count += 1
Output:
Q45-Write a Python program to calculate the sum of even and odd numbers in a list separately
sum_even = 0
sum_odd = 0
if num % 2 == 0:
sum_even += num
else:
sum_odd += num
Output:
s = "radar"
is_palindrome = s == s[::-1]
if is_palindrome:
print(f'"{s}" is a palindrome')
else:
Output:
"radar" is a palindrome
Q47-Check if the element 'banana' exists in the list l = ['apple', 'banana', 'cherry'].
if 'banana' in l:
else:
Output:
'banana' exists in the list
Q48-Sort the list l = [3, 1, 4, 1, 5, 9, 2, 6] in ascending order and print the sorted list.
l = [3, 1, 4, 1, 5, 9, 2, 6]
Output:
Q49-Convert the list l = [1, 2, 3] into a tuple t and convert the tuple t = (4, 5, 6) into a list. Print both
l = [1, 2, 3]
t = tuple(l)
t = (4, 5, 6)
list_from_tuple = list(t)
Output:
Tuple from list: (4, 5, 6)
Q50- Create two lists l1 with elements [1, 2, 3] and l2 with elements [4, 5, 6]. Concatenate them into a
single list l3 and print l3.
l1 = [1, 2, 3]
l2 = [4, 5, 6]
l3 = l1 + l2
print("Concatenated list:", l3)
Output:
Q51-Create a tuple t with elements (1, 2, 3, 4, 5) and print the element at index 3.
t = (1, 2, 3, 4, 5)
Output:
Element at index 3: 4
Q52-Create two tuples t1 with elements (1, 2, 3) and t2 with elements (4, 5, 6). Concatenate them into a
single tuple t3 and print t3
t1 = (1, 2, 3)
t2 = (4, 5, 6)
t3 = t1 + t2
Output:
Q53-Create a tuple t with elements (10, 20, 30, 40, 50). Print the first and last element.
Output:
First element: 10
Last element: 50
Q54-Create a tuple t with elements (10, 20, 30, 40, 50). Print the length of the tuple
length = len(t)
Output:
t = (5, 1, 8, 3, 9, 2)
max_element = max(t)
min_element = min(t)
Output:
Maximum element: 9
Minimum element: 1
Q56-Create a list l = ['apple', 'banana', 'cherry']. Find the index of the element 'banana'.
index_of_banana = l.index('banana')
Output:
Index of 'banana': 1
Q57-Remove duplicates from the list l = [1, 2, 3, 2, 4, 5, 1] and print the list without duplicates
l = [1, 2, 3, 2, 4, 5, 1]
l_no_duplicates = list(set(l))
Output:
List without duplicates: [1, 2, 3, 4, 5]
Q58-Write a Python program to swap the case of all characters in the string "Hello World"
s = "Hello World"
swapped_case = s.swapcase()
Output:
Swapped case: hELLO wORLD
Q59-Write a Python program to remove leading and trailing whitespace from the string " hello world"
trimmed_string = s.strip()
print("String without leading and trailing whitespace:", trimmed_string)
Q60-Write a Python program to find the index of the character 'w' in the string "hello world".
s = "hello world"
index_of_w = s.index('w')
Output:
Index of 'w': 6
Q61-Write a Python program to remove all punctuation from the string "hello, world!".
import string
s = "hello, world!"
Output:
s="hello world"
uppercased_string = s.upper()
Output:
s = "OpenAI"
length = len(s)
Output:
Q64-Write a Python program to split the string "hello world" into a list of words.
s = "hello world"
words_list = s.split()
print("List of words:", words_list)
Output:
Q65-Write a Python program to join the list ['hello', 'world'] into a single string with spaces.
Output:
Joined string: hello world