Lab 1 - QuestionsAns
Lab 1 - QuestionsAns
a = 5
b = 10
# Input string
s = "AI is the future of AI"
if(sorted(s1)== sorted(s2)):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")
for i in range(len(a)):
a[i] = int(a[i])
print(a)
for i in range(len(f)):
f[i] = int(f[i])
print(f)
formatted_value = f"{value:.2f}"
print(formatted_value)
a, b = 2, 3
value = a + b
ans = value * value
print("Output: ", ans)
9. Given a string mathematical expression, evaluate it (search for a function that can help you!)
10. Write a Python program that searches for the first multiple of 7 in a list using a while loop and stops
immediately when found (using break).
11. Create a secret code-breaking game where the player has three attempts to guess the correct password
"AI2024".
a. If the user guesses correctly, print "Access Granted!" and exit.
b. If they run out of attempts, print "Access Denied!"
password = "AI2024"
attempts = 3
if attempts == 0:
print("Access Denied!")
12. Write a Python function called calculate_total that accepts a list of prices:
a. Takes prices (price1, price2, price3,...) and returns their total sum
b. Includes a default argument (discount) that subtracts a discount from the total.
c. Accepts a keyword argument (detailed): If detailed=True, return a formatted breakdown instead of
just the total price.
def calculate_total(prices, discount=0, detailed=False):
total = sum(prices)
13. Given the following NumPy array representing a dataset of student scores across different subjects:
a. Extract the scores of the first two students.
b. Sort the scores of each student in descending order.
c. Extract all scores greater than 85.
import numpy as np