0% found this document useful (0 votes)
19 views

Python Lab

Uploaded by

Saksham Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python Lab

Uploaded by

Saksham Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

‭Python Programming Lab(BCC 302)‬

‭ .no.‬
S ‭ rogram‬
P
‭1‬ ‭Write a program that iterates over a dictionary of student names and their marks, printing each‬
‭student's name and marks.‬
‭‬
2 ‭Given a list of fruits fruits = ["apple", "banana", "cherry"], print each fruit using a for loop.‬
‭3‬ ‭Given two tuples (1, 2, 3) and (4, 5, 6), concatenate them and print the result.‬
‭4‬ ‭Write a program to replace all spaces in a string with hyphens using replace().‬
‭5‬ ‭Write a Python program to add a new key-value pair to a dictionary and update the value of an‬
‭existing key using update().‬
‭6‬ ‭Write a Python program to find the key with the highest value in the dictionary scores =‬
‭{"Alice": 85, "Bob": 90, "Charlie": 88}.‬
‭7‬ ‭Write a Python program that takes a string as input and counts the frequency of each word in‬
‭the string using a dictionary.‬
‭8‬ ‭Write a program that inputs a list of numbers and prints a new list with only the unique‬
‭elements.‬
‭9‬ ‭Write a Python program that takes a string, converts it into a list of characters, reverses the‬
‭list, and then joins it back into a string to print the reversed string.‬
‭10‬ ‭Write a Python program to store student information (name, age, course) using a dictionary,‬
‭and allow the user to input the details of multiple students. Later, print the details of each‬
‭student.‬

‭ .no.‬
S ‭ rogram‬
P
‭1‬ ‭Write a Python function fibonacci(n) that returns the nth Fibonacci number using recursion.‬
‭Test the function with different values of n.‬
‭‬
2 ‭Write a lambda function that takes two numbers as input and returns their sum.‬
‭3‬ ‭Write a Python program that demonstrates the difference between a local and a global‬
‭variable. Declare a global variable x = 10, then modify it locally inside a function and print the‬
‭results before and after the function call.‬
‭4‬ ‭Write a Python program to create a simple calculator that can add, subtract, multiply, and‬
‭divide using functions. Each operation should be a separate function.‬
‭5‬ ‭Write a function is_prime(n) that checks if a number is prime. Use this function inside a‬
‭program to check if a given number is prime or not.‬
‭6‬ ‭Write a function is_palindrome(s) that checks if a given string s is a palindrome (reads the‬
‭same forward and backward). Use this function inside a program to check different strings.‬
‭7‬ ‭Write a Python function find_largest(lst) that takes a list of numbers as input and returns the‬
‭largest number.‬
‭8‬ ‭Write a function celsius_to_fahrenheit(celsius) that converts Celsius to Fahrenheit and another‬
‭function fahrenheit_to_celsius(fahrenheit) that converts Fahrenheit to Celsius. Use these‬
‭functions in a program to perform the conversions.‬
‭9‬ ‭Write a function count_words(sentence) that takes a sentence as input and returns the number‬
‭of words in it.‬
‭10‬ ‭Write a function validate_password(password) that checks if a password meets the following‬
‭criteria:‬
‭●‬ ‭At least 8 characters long‬
‭●‬ ‭Contains both uppercase and lowercase characters‬
‭●‬ ‭Contains at least one number Use this function inside a program to validate‬
‭user-entered passwords.‬

You might also like