Python for Engineers-Assignments
Assignment-1
Date of submission-28 Sep 2023 Before 12:00pm
You have to generate a pdf file with question and answers and submit the print out
Python is developed by…….How Python got its name
Write the output of the statement 2**3**2
What is the difference between / and // operators. Write one example
How the expression 2+3*2**2/3 is evaluated show the order of evaluation and final output
How single line and multiline comments are added in Python script
Write the logical operators
What are bit wise operators
x=0xAA, y=0o16, z=0b10110 , find x^y|z
How to get the last bit of a number. Write the bitwise operation
e/g: x=2 o/p:1 x=3 o/p:1
x=12, what is the output of x<<2 justify your answer
What is a data type. What are the different data types in Python.
Define keyword. enumerate some of the keywords in python.
Basic Scripting
Write a Python script which will read two complex numbers(2+3j) and find their sum, difference and product.
Read your phone number and print the last two digit in binary, octal and hex.
Read a hexa decimal number and print the dec, bin and octal equivalent.
Given the center (xc,yc) and a point on the circle(x1,y1). Find the area
Write a Python program to read time in seconds and Print in HH:MM:SS format. i/p in seconds :1000 o/p:00:06:40
Use built in functions
Read a number and Print the corresponding binary, oct, hex
Read 3 numbers and find the largest and smallest
Use modules/packages
Print the month calendar depending on your DOB.
Eg: if the dob is 10/10/2004 the program should print 2004 October month calendar
Find the number of digits in the factorial of a given number
Find the sqrt of first and last digit of a number
Using if
Check whether the given year is leap year or not.
Write a python program to read a number and recursively add the digits in it Eg: i/p:123 o/p:6 i/p:78 o/p:6
Check whether the given number is power of 2 ( use bitwise operator)
Write a program to check the quadrant of a given point(x,y)( University question)
Write a program to get the absolute value of a number without using the abs() function.(university question)
Find the roots of a quadratic equation(ax^2+bx+c read a,b,c)
Write a program that accepts the length of three sides of a triangle as input and determine whether or not the triangle is a right triangle.( university question)
Using while/for
for c in range(25,15,-2):
c = c + 5
print(c, end=' ')
Generate the Fibonacci series 0 1 1 2 3 5 8…..n ( use while..read n)
Reverse a Number ( i/p: 123 o/P 321).Check whether th reverse is same as original number ( palindrome)
Check whether the given 3 digit number is Armstrong Number.
Eg:153 ( 1+125+27=153) sum of cubes of digits=number.
Check whether
the given number is a Krishnamurti number( Krishnamurthy Number: It is a number
which is equal to the sum of the factorials of all its digits.Use factorial()
function from math
For example : 145 = 1! + 4! + 5! = 1 + 24 + 120 = 145 which is a Krishnamurti
Number.
Check whether the given number is Prime or not.
Nested Loops(for/while)
Print all prime numbers less than 100.
Print the binary equivalent of each digit of the given number.
Print the multiplication table of numbers from (5-15)
******************************************************************************
Assignment-2
Date of submission-27 Oct 2023 Before 12:00pm
You have to generate a pdf file with question and answers and submit the print out
Learning outcome:Working with Strings
Outcome:Learn String Indexing and slicing, programming with strings
Consider the
string str="Python Programming by Yourname" ( Replace Yourname with
your first name)
Write statements in python to implement the following
a) To display the last four characters.
b) To display the substring starting from index 4 and ending at index 8.
c) Find the length of the string,min and max(characters)
d) To trim the last four characters from the string.
e) To trim the first four characters from the string.
f) To display the starting index of the substring 'gr'.
g) To change the case of the given string.( small letter to capital and capital
to small)
h) To check if the string is in title case.
i) To replace all the occurrences of letter 'm' in the string with '*'
j)reverse the string
k)count the occurrence of the character ‘m’
l)characters in even positions 0,2,4,…..
m) characters in even positions 0,2,4,…..in reverse order
n)check whether the substring ‘on’ is present in the string or not
o)Find the first occurrence of character ‘t’
p)convert the string into upper case
2. Write a program to check whether the given string is palindrome or not.
3. Count the vowels, digits,consonents, spaces in a string.
4. Read a binary number as a string and find its corresponding decimal
5. Read a decimal number and find its binary.( Hint: divide by 2 and append the reminder to a string)
6. Read an 8 bit binary number and print the hex equivalent
7. Read a two digit hex number and print the binary and decimal equivalent.
8. Read a string and swap the case ( small lettesr to capital letters and capital letters to small letters)
9. Encrypt a string using the shift cipher( key=3 Ceaser cipher)
10. Write a Python program to check the validity of a password given by the user.
The Password should satisfy the following criteria:
1. Contains at least one letter between a and z
2. Contains at least one number between 0 and 9
3. Contains at least one letter between A and Z
4. Contains at least one special character from $, #, @
5.Minimum length of password: 8
Learning outcome: Learn list, tuple and set
1. Write commands for the following
a. Create an empty list (stud)
b. Add your roll number to the list (use + operator)
c. Append your name (use append)
d. Extend the list with your place and pin and mobile number (extend)
e. Insert your KTU-ID at stud [0]
f. Print your KTU-ID and name
g. Print the number of characters in your name.
h. Print last 5 digit of the phone number
I.Reverse the stud list
j.Find the index of your name.
3. Read list of students names and do the following
a) Sort the name in alphabetical order
b) Find the name with largest length
c)print the names starting with letter ‘A’ ( assume first letter capital)
d) Print the names in reverse alphabetical order with all names converted to capital letters.
e) Print the names in the order of length
4. Use list comprehension to create lists
a)powers of 3 upto 20
b) Numbers less than 100 which are divisible by 3
5. Read 10 numbers and stores it in a tuple. Find the sum, average of these elements also find the largest and smallest.
6. Find the union, intersection and symmetric difference of two sets A and B. Read the sets.
7.Read a string and print the words in alphabetical order
8.Read a string and print the words and its legth.Also find the average word length.
9.Read list of numbers and find the mean, median and standard deviation.
10. Consider a list consisting of integers, floating point numbers and strings. Separate them into different lists depending on the data types.
11. Check if the items in the list are sorted in ascending or descending order and print suitable messages accordingly. Otherwise, print “Items in list are not sorted”
12.Remove all duplicate elements from a list i/p:10 20 20 30 40 o/p:10 30 40
13.Find the number with largest frequency of occurrence. i/p:10 20 30 40 40 40 50 50 o/p:40
( Note: there may be more than one element)
Comments
Post a Comment