Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Assignment 3 - Python Programming (1)

The document outlines a lab assignment consisting of five Python programming tasks. These tasks include creating functions to return unique elements from a list, print even numbers, check if a number is within a range, sum numbers in a list, and count uppercase and lowercase letters in a string. Each task includes a brief description and a sample solution code.

Uploaded by

vtggamer1030
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 3 - Python Programming (1)

The document outlines a lab assignment consisting of five Python programming tasks. These tasks include creating functions to return unique elements from a list, print even numbers, check if a number is within a range, sum numbers in a list, and count uppercase and lowercase letters in a string. Each task includes a brief description and a sample solution code.

Uploaded by

vtggamer1030
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Assignment-Function

1) Write a Python function that takes a list and returns a


new list with unique elements of the first list.

Solution: paste code and screenshot of output

def unique_elements_from_user():

user_input = input("Enter a list of numbers: ")

input_list = list(map(int, user_input.split()))

unique_list = list(dict.fromkeys(input_list))

print("Unique elements:", unique_list)

unique_elements_from_user()

2) Write a Python program to print the even numbers from a


given list.

Solution: paste code and screenshot of output

def print_even_numbers():

user_input = input("Enter a list of numbers: ")

numbers = list(map(int, user_input.split()))

even_numbers = [num for num in numbers if num % 2 == 0]

print("Even numbers:", even_numbers)

print_even_numbers()
3) Write a Python function to check whether a number is in a
given range.

Solution: paste code and screenshot of output

def check_number_in_range():
number = int(input("Enter a number to check: "))
start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))
if start <= number <= end:
print(f"{number} is in the range [{start}, {end}].")
else:
print(f"{number} is not in the range [{start}, {end}].")
check_number_in_range()

4) Write a Python function to sum all the numbers in a list

def sum_of_list_from_user():
user_input = input("Enter a list of numbers: ")
numbers = list(map(int, user_input.split()))
total = sum(numbers)
print(f"The sum of {numbers} is {total}.")
sum_of_list_from_user()
5) Write a Python function that accepts a string and calculate
the number of upper case letters and lower case letters.

Solution: paste code and screenshot of output

def count_case_letters_from_user():
input_string = input("Enter a string: ")
upper, lower = count_case_letters(input_string)
print(f"Uppercase letters: {upper}")
print(f"Lowercase letters: {lower}")
count_case_letters_from_user()
.

You might also like