1. Write a program in python to Plotting x and y point arrays on a plot.
import [Link] as plt
# x axis values
x = [1,2,3]
# corresponding y axis values
y = [2,4,1]
# plotting the points
[Link](x, y)
# naming the x axis
[Link]('x - axis')
# naming the y axis
[Link]('y - axis')
# giving a title to my graph
[Link]('My first graph!')
# function to show the plot
[Link]()
2. Write a program to use different type of markers and line styles on the plot.
import [Link] as plt
import random as random
students = ["Jane", "Joe", "Beck", "Tom",
"Sam", "Eva", "Samuel", "Jack",
"Dana", "Ester", "Carla", "Steve",
"Fallon", "Liam", "Culhane", "Candance",
"Ana", "Mari", "Steffi", "Adam"]
marks = []
for i in range(0, len(students)):
[Link]([Link](0, 101))
[Link]("Students")
[Link]("Marks")
[Link]("CLASS RECORDS")
[Link](students, marks, 'm--')
# Adding grid lines
[Link](True, which='both', linestyle='--', linewidth=0.5)
[Link]()
3. Write a Python program to calculate the electricity bill. Accept the last meter reading
and current meter reading and the rate per unit from the user. Calculate the number of
units and total bill consumption for the user
# Python program to calculate electricity bill
# Function to calculate the electricity bill
def calculate_electricity_bill(last_meter_reading, current_meter_reading,
rate_per_unit):
# Calculate the number of units consumed
units_consumed = current_meter_reading - last_meter_reading
# Calculate the total bill
total_bill = units_consumed * rate_per_unit
return units_consumed, total_bill
# Input: last meter reading, current meter reading, and rate per unit
last_meter_reading = float(input("Enter the last meter reading: "))
current_meter_reading = float(input("Enter the current meter reading: "))
rate_per_unit = float(input("Enter the rate per unit: "))
# Calculate units consumed and total bill
units_consumed, total_bill = calculate_electricity_bill(last_meter_reading,
current_meter_reading, rate_per_unit)
# Display the results
print(f"Units Consumed: {units_consumed}")
print(f"Total Bill: ${total_bill:.2f}")
4. Write a program to determine if two strings are anagrams (i.e., they have the same
characters in a different order).
def are_anagrams(str1, str2):
# Sort both strings and compare
return sorted(str1) == sorted(str2)
# Input two strings
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
# Check and print result
if are_anagrams(string1, string2):
print("The two strings are anagrams.")
else:
print("The two strings are not anagrams.")
5. Write a program to do linear search.
# Function to perform linear search
def linear_search(arr, target):
# Iterate through each element in the list
for i in range(len(arr)):
if arr[i] == target: # Check if current element matches the target
return i # Return the index if the target is found
return -1 # Return -1 if the target is not found in the list
arr = [10, 23, 45, 70, 11, 15]
target = int(input("Enter the element to search for: "))
result = linear_search(arr, target)
if result != -1:
print(f"Element found at index {result}")
else:
print("Element not found in the list")