Showing posts with label assignments. Show all posts
Showing posts with label assignments. Show all posts
PYTHON ASSIGNMENT 10 - LIST COMPREHENSION
Write
a list comprehension that prints a list of the cubes of the numbers 1 through
10.
Write
a list comprehension that prints out the possible results of two coin flips (example
- one result would be ’ht’)
Write
a function that takes in a string and uses a list comprehension to return all
the vowels in the string.
Run
this list comprehension in your prompt:
[x+y
for x in [10, 20, 30] for y in [1, 2, 3]]
Write
a function that takes in a list of elements of different types and uses a list
comprehension to return all the elements of the list of type int. (Note: Use the
python isinstance function)
Write
a list comprehension which solves the equation y = x2+1. The solution should
print out a list of [x, y] pairs; use the domain x ∈ [−5, 5] and the range y ∈
[0, 10].
Write
a list comprehension that finds the integer solutions [x, y] for a circle of
radius 5.
PYTHON - EXTRA ASSIGNMENT PROGRAMS
Control Structure
Check
if a given number is divisible by 5
Sum
of N different numbers
Sum
and average of N different numbers
Sum
of numbers between 1 and 50 which are divisible by 3 and not by 5
First
N even numbers
First
N numbers divisible by 4
Functions
Area
and circumference of a circle
Simple
and Compound Interest
Smallest
and largest digit in a number
Sum
of digits of a number until single number is obtained
Sum
of even and odd digits of a number
Sum
of squares of individual digits of a number
Sum
of cubes of individual digits of a number
Digits
in odd position of a number
Digits
in even position of a number
Factorial
of first N numbers
Read
a name and display a welcome message
Menu
driven Calculator program
Lists
Create
a list and perform the following operations on the list
Display
content of list
Display
length of list
Display
element in given position in the list
Add
elements to the list
Remove
elements from the list:
Slice
Sort
Reverse
Replace
elements
Join
two lists
Membership
test
Nested
lists
Lists and Functions
Smallest
number from a set of numbers
Largest
number from a set of numbers
Sum
of even and odd numbers from a set of numbers
Sort
the elements of a matrix
Read
an N x N matrix. Check if the last element of each row is the sum of the all
other elements in that row
String
Two
words form a metathesis pair, if you can transform one into the other by
swapping two letters. Example – conserve and converse. Write a program to find
all the metathesis pair in a dictionary.
Read
a word and check if all the letters are in alphabetical order
Two
words are anagrams if you can rearrange the letters from one to spell the
other. Write a program that displays all lists of anagrams from the word list. Example:
[‘silent’,
‘listen’]
[‘deltas’,’desalt’,’lasted’,’salted’,’slated’,’staled’]
Two
words are reverse pair, if each is the reverse of the other. Example: was and
saw. Write a program that finds all the reverse pairs in the word list.
Two
words “interlock” if taking alternate letters from each forms a new word.
Example, “shoe” and “cold” interlock to form “schooled”. Write a program that
finds all pairs of words that interlock.
Dictionary
Creating
a Dictionary and perform the following operations:
Get
the values in a Dictionary
Looping
over dictionary
Add
elements to a dictionary
combine
two dictionaries
Delete
elements of a dictionary
Test
the presence of a key
Write
a program to generate a dictionary containing the list of customers and their
telephone numbers. Write functions to find the telephone number of a given
customer and to find the customer details if the telephone number is specified.
Files
Read
a file and display all words containing all 5 vowels atleast once. Example –
automobile
Write
a program called cross reference that creates a dictionary of all words in a
document, and for each word, a list of the line numbers on which it occurs.
Remove noise words like “the”, “and”, and so on.
Write
a program to compare two files, printing the first line where they differ.
Write
a program that displays the three most frequently occurring words in a file.
Write
a program that displays five most frequently occurring characters in a file.
Given
a file containing customer names and their phone numbers, write a program to
find the telephone number of a given customer.
Write
a program to read student details (Name, roll number and CGPA) and write to
file. Also display the file content.
PYTHON ASSIGNMENT 9: FILES
Read from console and write to file
Read from file and display in console
Display file content with line number
Display first N lines of a file
Display nth line of a file
Display from nth line to mth line of a file
Copy file
Copy first N lines from a file to new file
Copy from nth line to mth line of a file to new file
Merge two files
Count number of characters, words and lines in a file
Search if a word exists in a file.
Count number of times a word exists in a file
Search if a word exists in a file. Display all lines in which the word
exists.
Delete a word in a file
Replace a word in a file
Write a program that creates a dictionary of the frequency of all words in
a file. Remove noise words like “the”, “and”, and so on. Display the three most
frequently occurring words.
Write a program that creates a dictionary of the frequency of all the
characters in a file. Display five most frequently occurring characters.
Given a file containing customer names and their phone numbers, write a
program to find the telephone number of a given customer.
Compare two files and print the first line where they differ.
PYTHON ASSIGNMENT 8: FUNCTIONS
Check if a given number is even or odd
Find sum of two numbers
Swap two numbers
Biggest of three numbers
Find GCD of two numbers
Find distance between two points
Find square root of a number using Newton’s method
Check if a given number is an Armstrong number
Check if a given number is a prime number
Number manipulation
Number of digits
Sum of digits
Reverse of a number
Factorial of a number using (1) iteration and (2) recursion
Fibonacci series up to (1) a given limit and (2) number of terms
List
Sum of elements
Average of all numbers
Biggest element
Smallest element
Read two lists and merge without duplicates
Matrix Manipulation
Addition
Subtraction
Multiplication
Sum of diagonal element
Transpose of a matrix
PYTHON ASSIGNMENT 7: MISCELLANEOUS PROGRAMS
Operators and Control Structures
Swap two numbers
Circulate the values of n variables
Find GCD of two numbers
Distance between two points
Square root of a number using Newton’s method
Exponentiation of a number
First N prime numbers
List
Maximum in a given list of numbers
Sum of elements in a list
Matrix multiplication
Search
Linear search
Binary search
Sort
Insertion sort
Selection sort
Merge sort
Dictionaries : Histograms
Read a string and find the 5 most frequent characters
Read a string and find the 3 most frequent words
File operations:
File copy
Merge two files
Read a file name from command line and count the number of lines, words and characters in the file.
Read a file and create a dictionary for the frequency of words in the file
Read a file and create a dictionary for the frequency of characters in the file.
PYTHON ASSIGNMENT 6: DICTIONARIES
Write a program to generate a dictionary called phonebook containing the list of customers and their telephone numbers.
Lookup: Read a customer name and print the associated entry from the phonebook on a new line in the form name=phonenumber; If an entry for name is not found, print “Not found" instead.
Reverse Lookup: Given a phone number find the customer details. If number is not present, print “No match found”
Create a dictionary containing employee name and id (name:id). Display
Employee names, sorted in alphabetical order
Employee name and id, sorted alphabetically by name
Inverse the dictionary (id : name)
Consider two lists
NAMES = [’Alice’, ’Bob’, ’Cathy’, ’Dan’, ’Ed’, ’Frank’, ’Gary’, ’Helen’, ’Irene’, ’Jack’, ’Kelly’, ’Larry’]
AGES = [20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19]
These lists match up, so Alice’s age is 20, Bob’s age is 21, and so on. Write a program that
Combines these lists into a dictionary.
Reads a name and returns the age.
Reads an age and returns the names of all the people who are that age.
Histogram: Read a string and create a dictionary containing the frequency of the characters in string.
Histogram: Read a string and create a dictionary containing the frequency of the words in string.
PYTHON ASSIGNMENT 5: LISTS
Write a program to read a set of numbers from a user and store in a list. Eliminate duplicate elements.
Given a list of N numbers, read the element to search in the list. Display the number of occurrences of the element with its position.
Anagrams. Given a list of words display the sets of anagrams.
Given a list of integers, create a new list with cumulative sum; that is a new list where the ith element is the sum of the first i elements from the original list. For example, the cumulative sum of [4, 3, 6] is [4, 7, 13].
Create a nested list containing student details (Roll number, name and 3 marks). Print the roll number, name, total and average marks of each student.
Given two lists that are sorted in ascending order, write a program to merge the lists into a single list that contains every item from both lists in sorted order.
Matrix
Addition, subtraction and multiplication of matrices.
Transpose of a matrix.
Sum of diagonal elements of a matrix.
Largest, smallest element in matrix.
Subscribe to:
Posts (Atom)




















