KEMBAR78
Class10 Robotics AI Python Programs | PDF | Computer Programming
0% found this document useful (0 votes)
14 views2 pages

Class10 Robotics AI Python Programs

Uploaded by

ehtsalman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Class10 Robotics AI Python Programs

Uploaded by

ehtsalman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Student List Sorter


# Program to input a list of student names and display them sorted names = input("Enter student
names separated by commas: ").split(',') names = [name.strip() for name in names]
names.sort(key=lambda x: x.lower()) print("Sorted Names:", names)
Sample Run: Input: John, Alice, bob Output: Sorted Names: ['Alice', 'bob', 'John']

2. Find Word in Sentence


# Program to find a word in a given sentence sentence = input("Enter a sentence: ") word =
input("Enter word to search: ") if word.lower() in sentence.lower().split(): print(f"'{word}' found in the
sentence") else: print(f"'{word}' not found")
Sample Run: Input: sentence='I like robotics', word='robotics' Output: 'robotics' found in the
sentence

3. City-Data Dictionary
# Program to store and query city temperature data city_data = {"Delhi": 30, "Mumbai": 28,
"Kolkata": 29} city = input("Enter city name: ") if city in city_data: print("Average temperature:",
city_data[city], "°C") else: print("City not found")
Sample Run: Input: city='Delhi' Output: Average temperature: 30 °C

4. Electricity Bill Calculator


# Program to calculate electricity bill prev = int(input("Enter previous meter reading: ")) curr =
int(input("Enter current meter reading: ")) units = curr - prev bill = 0 if units <= 100: bill = units * 5 elif
units <= 300: bill = 100*5 + (units-100)*7 else: bill = 100*5 + 200*7 + (units-300)*10 print("Total Bill:
Rs.", bill)
Sample Run: Input: prev=1200, curr=1350 Output: Total Bill: Rs. 850

5. Bonus Calculator
# Program to calculate bonus based on years of service salary = float(input("Enter salary: ")) years
= int(input("Enter years of service: ")) if years > 5: bonus = salary * 0.05 else: bonus = 0
print("Bonus Amount: Rs.", bonus)
Sample Run: Input: salary=50000, years=6 Output: Bonus Amount: Rs. 2500.0

6. NumPy Array Operations


import numpy as np arr = np.array([1,2,3,4,5]) print("Array:", arr) print("Mean:", np.mean(arr))
print("Reshaped (5x1):", arr.reshape(5,1))
Sample Run: Output: Array: [1 2 3 4 5] Mean: 3.0 Reshaped: [[1],[2],[3],[4],[5]]

7. Plot Data using Matplotlib


import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.plot(x, y, marker='o')
plt.xlabel('X values') plt.ylabel('Y values') plt.title('Simple Line Graph') plt.show()
Sample Run: Displays a line graph of x vs y.
8. Predict Temperature Trend
from sklearn.linear_model import LinearRegression import numpy as np # Example data: year vs
temperature X = np.array([[2000],[2005],[2010],[2015],[2020]]) y = np.array([30, 31, 32, 33, 34])
model = LinearRegression().fit(X, y) next_year = np.array([[2025]]) pred = model.predict(next_year)
print("Predicted temperature in 2025:", pred[0])
Sample Run: Output: Predicted temperature in 2025: 35.0 (approx)

9. Text Processing
# Count words and check palindrome text = input("Enter text: ") print("Word Count:", len(text.split()))
if text.lower() == text.lower()[::-1]: print("It is a palindrome") else: print("Not a palindrome")
Sample Run: Input: 'madam' Output: Word Count: 1, It is a palindrome

10. Dice Roll Simulation


import random print("Rolling dice...") print("You got:", random.randint(1,6))
Sample Run: Output: You got: 4

You might also like