Ai Practicalfile
Ai Practicalfile
Intelligence
Class: Xth C
def calculate_nrr(total_runs_scored,
total_overs_faced, total_runs_conceded,
total_overs_bowled):
# Calculate NRR
batting_rate = total_runs_scored / total_overs_faced
bowling_rate = total_runs_conceded /
total_overs_bowled
nrr = batting_rate - bowling_rate
return nrr
# Example inputs for a team
total_runs_scored = float(input("Enter the total runs
scored by the team: "))
total_overs_faced = float(input("Enter the total overs
faced by the team: "))
total_runs_conceded = float(input("Enter the total runs
conceded by the team: "))
total_overs_bowled = float(input("Enter the total overs
bowled by the team: "))
# Calculate NRR
nrr = calculate_nrr(total_runs_scored,
total_overs_faced, total_runs_conceded,
total_overs_bowled)
# Output the result
print(f"The Net Run Rate (NRR) of the team is: {nrr:.2f}")
A program to check whether the given
character is an uppercase letter or
lowercase letter or a digit or a special
character.
def check_character(char):
# Check if the character is an uppercase letter
if char.isupper():
return "Uppercase letter"
# Check if the character is a lowercase letter
elif char.islower():
return "Lowercase letter"
# Check if the character is a digit
elif char.isdigit():
return "Digit"
# If it's none of the above, it's a special character
else:
return "Special character"
# Take input from the user
char = input("Enter a character: ")
# Ensure that only one character is entered
if len(char) == 1:
result = check_character(char)
print(f"The character '{char}' is a {result}.")
else:
print("Please enter exactly one character.")
A program to find the maximum
number out of the given three
numbers.
def calculate_bill(units_consumed):
if units_consumed <= 100:
# Rate for 0-100 units
return units_consumed * 1
elif units_consumed <= 300:
# Rate for 101-300 units
return 100 + (units_consumed - 100) * 1.25
elif units_consumed <= 500:
# Rate for 301-500 units
return 350 + (units_consumed - 300) * 1.50
else:
# Rate for 500+ units
return 650 + (units_consumed - 500) * 1.75
# Input: customer number and power consumed
customer_number = input("Enter customer number: ")
units_consumed = float(input("Enter units of power
consumed: "))
# Calculate the bill amount
amount = calc
A a program to check whether the
entered number is Armstrong or
not.
def is_armstrong(number):
# Convert the number to a string to easily extract
digits
num_str = str(number)
num_digits = len(num_str)
# Calculate the sum of the digits raised to the power
of the number of digits
sum_of_powers = sum(int(digit) ** num_digits for
digit in num_str)
# Check if the sum of powers equals the original
number
return sum_of_powers == number
# Input: number from the user
num = int(input("Enter a number to check if it's an
Armstrong number: "))
# Check if the number is an Armstrong number
if is_armstrong(num):
print(f"{num} is an Armstrong number.")
else:
print(f"{num} is not an Armstrong number.")
A a program to print a
multiplication table of the entered
number
Class: Xth C