1.
Write a python program for temperature print(f"the speed of the vehicle is {speed} km/hr")
converter.
OUTPUT:
celsius = 20
Enter the distance traveled
print("celsius:",celsius) :490.6
fahrenheit = (celsius * 9/5) + 32 Enter the time:2
print("celsius to fahrenheit:",fahrenheit) the speed of the vehicle is 245.3
km/hr
kelvin = 273.15 + celsius
3. Write a python program to calculate
print("celsius to kelvin:",kelvin) percentage of 6 subject.
fahrenheit = 14 Marathi=42
print('fahrenheit:',fahrenheit) Hindi=41
celsius = (fahrenheit-32) * 5/9 English=48
print("fahrenheit to celsius:",celsius) EVS=40
kelvin = (5/9) * (fahrenheit - 32) + 273.15 Mathematics=50
print("fahrenheit to kelvin:", kelvin) Geography=35
kelvin= -203.6 Total=(Marathi+Hindi+English+EVS+Mathematics
print('kelvin:',kelvin) +Geography)
celsius = kelvin-273.15 Percentage=(Total/300)*100
print('kelvin to celsius:',celsius) print("Percentage=",Percentage)
fahrenheit = (9/5) * (kelvin-273.15) + 32 OUTPUT:
Percentage= 85.33333333333334
print('kelvin to fahrenheit:',fahrenheit)
OUTPUT:
4. Write a python program to compare the
celsius: 20
celsius to fahrenheit: 68.0 string.
celsius to kelvin: 293.15 a =str(input("Enter a string: "))
fahrenheit: 14
fahrenheit to celsius: -10.0 b =str(input("Enter a another string: "))
fahrenheit to kelvin: 263.15
kelvin: -203.6 if a==b:
kelvin to celsius: -476.75
kelvin to fahrenheit: -826.15 print("Both are Same")
else:
2. Write a python program for calculating speed print("Not same")
of vehicle.
OUTPUT:
distance=float(input("Enter the distance traveled
:")) Enter a string: Python
Enter a another string: Python
time=float(input("Enter the time:"))
Both are Same
speed=distance / time
5. Write a python program to Arrange string pos = text_lower.find(substring_lower, start)
characters such that lowercase letters should
if pos == -1: # No more occurrences
come first.
break
text = input("Enter a string: ")
positions.append(pos) # Save the position
# Separate lowercase and uppercase letters
start = pos + 1 # Move to the next character
lowercase_letters = ""
print("Occurrences found at positions:",
uppercase_letters = ""
positions)
for char in text:
OUTPUT:
if char.islower(): # Check if the character is
Occurrences found at positions:
lowercase [3]
lowercase_letters += char
elif char.isupper(): # Check if the character is
uppercase
uppercase_letters += char
result = lowercase_letters + uppercase_letters
print("Arranged string:", result)
OUTPUT:
Enter a string: InteLLiGencE
Arranged string: nteiencILLGE
6. Write a python program to Find all
occurrences of a substring in a given string by
ignoring the case.
# Input string and substring
text = "Hello world, hello everyone!"
substring = "hello"
# Convert both to lowercase to ignore case
text_lower = text.lower()
substring_lower = substring.lower()
# Find occurrences
positions = []
start = 0
while start < len(text_lower):
# Find the next occurrence
myList = [10, 40, 50, 20, 30, 10, 40, 10] Descending by length: ['small',
'foxes', 'saw', 'six', 'he']
yourList = ['saw', 'small', 'foxes', 'he', 'six']
#5. Add float value 3.5 into yourList
# 1. Append integer 60 into myList
yourList.append(3.5)
myList.append(60)
print(yourList)
print(myList)
OUTPUT: ['saw', 'small', 'foxes',
OUTPUT: [10, 40, 50, 20, 30, 10, 'he', 'six', 3.5]
40, 10, 60]
#6. Use POP and remove method to remove 3.5
#2. Insert 70 on 2nd position
b=yourList.pop(5)
myList.insert(1,70)
print("poped number is",b)
print(myList)
print(yourList)
OUTPUT: [10, 70, 40, 50, 20, 30,
10, 40, 10, 60] OUTPUT: poped number is 3.5
#3. Sort myList in ascending and descending ['saw', 'small', 'foxes', 'he',
order 'six']
myList.sort() #7. Create ourList by merging myList and
yourList.
print("Ascending order:",myList)
ourList= myList+yourList
myList.sort(reverse=True)
print(ourList)
print("Descending order:",myList)
OUTPUT:
OUTPUT:
[70, 60, 50, 40, 40, 30, 20, 10,
Ascending order: [10, 10, 10, 20, 10, 10, 'saw', 'small', 'foxes',
30, 40, 40, 50, 60, 70] 'he', 'six']
Descending order: [70, 60, 50, #8. Find sum of elements in myList
40, 40, 30, 20, 10, 10, 10]
a=sum(myList)
#4. Sort yourList in ascending and descending
according to length of strings. print(a)
ascending_by_length = sorted(yourList, key=len) OUTPUT: 340
descending_by_length = sorted(yourList, key=len, #9. Find smallest, largest and second largest
reverse=True) number in a myList
print("Ascending by length:", c=min(myList)
ascending_by_length)
print(c)
print("Descending by length:",
d=max(myList)
descending_by_length)
print(d)
OUTPUT:
#second largest
Ascending by length: ['he',
'saw', 'six', 'small', 'foxes'] myList.sort()
print(myList)
g=myList[-2] 11. Perform Data slicing to display string
elements from ascending sorted yourList as:-
print("Second largest:",g)
a. Display-‘saw’,’six’,’small’
OUTPUT:
b. Use negative indices to display – ‘six’, ‘small’,
10
‘foxes’
70
c. All elements after mid of the list (In both
[10, 10, 10, 20, 30, 40, 40, 50, directions)
60, 70]
Alternate elements in both direction middle of list
Second largest: 60
#10. Count occurrences of all element in a list
yourlist=['saw','small','foxes','he','six']
from collections import Counter
yourlist.sort()
myList = [10, 40, 50, 20, 30, 10, 40, 10]
print(yourlist)
# Count occurrences
print(yourlist[2:])
count_myList = Counter(myList)
print(yourlist[-3:])
print(count_myList)
print(yourlist[::2])
OUTPUT:
OUTPUT:
Counter({10: 3, 40: 2, 20: 1, 30:
1, 50: 1, 60: 1, 70: 1}) ['foxes', 'he', 'saw', 'six',
'small']
['saw', 'six', 'small']
['saw', 'six', 'small']
['foxes', 'saw', 'small']