PROGRAM - 1
Q - Program to input radius of the Circle and print Area and Circumference.
INPUT-
radius = float(input("Enter the radius of the circle: "))
pi = 3.14
area = pi * radius ** 2
circumference = 2 * pi * radius
print("Area of the circle:", area)
print("Circumference of the circle:", round(circumference, 2))
OUTPUT-
PROGRAM - 2
Q - Program to input sale amount, cost amount and check whether there is a
profit or loss or no profit, no loss.
INPUT-
sale_amount = float(input("Enter the sale amount: "))
cost_amount = float(input("Enter the cost amount: "))
if sale_amount > cost_amount:
print("Profit")
elif sale_amount < cost_amount:
print("Loss")
else:
print("No profit, no loss")
OUTPUT-
PROGRAM -3
Q - Program to input an Integer and print its multiplication table.
INPUT-
# Input an integer
num = int(input("Enter an integer: "))
# Print multiplication table
for i in range(1, 11):
print(num, "x",i,"=",num * i)
OUTPUT-
PROGRAM -4
Q - Program to print first 10 terms of Fibonacci series.
INPUT-
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
# Print first 10 terms of Fibonacci series
fibonacci(10)
OUTPUT-
PROGRAM -5
Q - Program to input character and check whether the given character is
alphabet , digit or any other character .
INPUT-
# Input from the user
char = input("Enter a character: ")
# Check and display the result
if char.isalpha():
print( "The character is an alphabet.")
elif char.isdigit():
print ("The character is a digit.")
else:
print ("The character is a special character.")
OUTPUT-
PROGRAM -6
Q - Program to input a number and check whether it is palindrome or not.
INPUT-
# Input a number from the user
number = int(input("Enter a number: "))
# Convert the number to a string
num_str = str(number)
# Check if the string is equal to its reverse
if num_str == num_str[::-1]:
print(number,"is a palindrome.")
else:
print(number,"is not a palindrome.")
OUTPUT-
PROGRAM -7
Q - Program to generate random number between 1 to 6 (stimulates dice )
INPUT-
import random
def roll_dice():
return random.randint(1, 6)
if __name__ == "__main__":
print("Rolling the dice...")
print("The number is:", roll_dice())
print("Rolling the dice again...")
print("The number is: ", roll_dice())
OUTPUT-
PROGRAM -8
Q - Program to input an Integer form user and print sum of its digits.
INPUT-
# Program to input an integer from user and print sum of its digits
def sum_of_digits(number):
return sum(int(digit) for digit in str(number))
user_input = int(input("Enter an integer: "))
print("The sum of the digits is:",sum_of_digits(user_input))
OUTPUT-
PROGRAM -9
Q - Program to input a string from user and print number of vowels and
consonant present in the string
INPUT-
def count_vowels_and_consonants(input_string):
vowels = "aeiouAEIOU"
num_vowels = 0
num_consonants = 0
for char in input_string:
if char.isalpha():
if char in vowels:
num_vowels += 1
else:
num_consonants += 1
return num_vowels, num_consonants
# Input string from user
user_input = input("Enter a string: ")
vowels, consonants = count_vowels_and_consonants(user_input)
print(f"Number of vowels: {vowels}")
print(f"Number of consonants: {consonants}")
OUTPUT-
PROGRAM -10
Q - Program to input a string form a user and then print ther longest word in
the string
INPUT-
def find_longest_word(sentence):
words = sentence.split()
longest_word = max(words, key=len)
return longest_word
# Input string from user
user_input = input("Enter a string: ")
longest_word = find_longest_word(user_input)
print("The longest word is:", longest_word)
OUTPUT-
PROGRAM -11
Q Program to input string from user and then convert uppercase to lowercase
and lowercase to uppercase
INPUT-
# Input string from user and convert case
user_input = input("Enter a string: ")
result = user_input.swapcase()
# Display the result
print("Converted string:", result)
OUTPUT-
PROGRAM -12
Q - Program to input ‘n’ numbers from the user and store it into a list
INPUT-
# Program to input 'n' numbers from the user and store them into a list
# Function to input 'n' numbers and store them in a list
def input_numbers(n):
numbers = []
for _ in range(n):
number = float(input("Enter a number: "))
numbers.append(number)
return numbers
# Main code
n = int(input("How many numbers do you want to input? "))
numbers_list = input_numbers(n)
print("The numbers you entered are:", numbers_list)
OUTPUT-
PROGRAM -13
Q - Program to input a list of integers from the user then print sun of even
number and odd number separately.
INPUT-
# Function to calculate the sum of even and odd numbers in a list
def sum_even_odd(numbers):
sum_even = 0
sum_odd = 0
for num in numbers:
if num % 2 == 0:
sum_even += num
else:
sum_odd += num
return sum_even, sum_odd
# Input a list of integers from the user
numbers = list(map(int, input("Enter a list of integers separated by spaces:
").split()))
# Calculate the sums
sum_even, sum_odd = sum_even_odd(numbers)
# Print the results
print(f"Sum of even numbers: {sum_even}")
print(f"Sum of odd numbers: {sum_odd}")
OUTPUT-
PROGRAM -14
Q - Program to input a list of integers from the user then display its mean,
median and mode using statistics module.
INPUT-
import statistics
# Function to input a list of integers from the user
def input_list():
user_input = input("Enter a list of integers separated by spaces: ")
return list(map(int, user_input.split()))
# Main function
def main():
numbers = input_list()
mean = statistics.mean(numbers)
median = statistics.median(numbers)
mode = statistics.mode(numbers)
print(f"Mean: {mean}")
print(f"Median: {median}")
print(f"Mode: {mode}")
if __name__ == "__main__":
main()
OUTPUT-
PROGRAM -15
Q - Program to create a tuple which will store first ten natural numbers using
a loop then print the tuple
INPUT-
# Create a tuple to store the first ten natural numbers
natural_numbers = tuple(i for i in range(1, 11))
# Print the tuple
print(natural_numbers)
OUTPUT-
PROGRAM -16
Q - Program to input ‘n’ number in a tuple then find largest and smallest
value of tuple
INPUT-
# Program to input 'n' numbers in a tuple and find the largest and smallest values
# Function to get the largest and smallest values in a tuple
def find_largest_smallest(numbers):
largest = max(numbers)
smallest = min(numbers)
return largest, smallest
# Input the number of elements
n = int(input("Enter the number of elements in the tuple: "))
# Input the elements and create the tuple
elements = []
for i in range(n):
element = int(input(f"Enter element {i+1}: "))
elements.append(element)
numbers_tuple = tuple(elements)
# Find and display the largest and smallest values
largest, smallest = find_largest_smallest(numbers_tuple)
print(f"The largest value in the tuple is: {largest}")
print(f"The smallest value in the tuple is: {smallest}")
OUTPUT-
PROGRAM -17
Q - Program to input lower limit of a range then print any three random
numbers in this range
INPUT-
import random
# Input lower limit of the range
lower_limit = int(input("Enter the lower limit of the range: "))
# Generate and print three random numbers in the range
for _ in range(3):
random_number = random.randint(lower_limit, lower_limit + 100) #
Assuming an upper limit for the range
print(random_number)
OUTPUT-