Input import cmath a = int(input("Enter the value for a: ")) b = int(input("Enter the value for b: ")) c = int(input("Enter the value for...
Python Practicals
Syllabus with topics linked
Write a program to accept a number ‘n’ and check these conditions
Write a program to accept a number ‘n’ and check a). Check if ’n’ is prime. b). Generate all prime numbers till ‘n’. c). Generate first...
Write a program to create a pyramid of the character ‘*’ and a reverse pyramid
Input def pyramid(n): k = n - 1 for i in range(n): for j in range(0, k): print(end=" ") k -= 1 for j in range(0, (2 * i) + 1): print("* ",...
Write a program that accepts a character and performs the following
Write a program that accepts a character and performs the following: a.) print whether the character is a letter, numeric digit, or a...
Write a program to perform the following operations on a string
Write a program to perform the following operations on a string: a.) Find the frequency of a character in a string. b.) Replace a...
Write a program to swap the first n characters of two strings.
Input test1 = input("enter the first string \n") test2 = input("enter the second string \n") to_swap = int(input("enter the number of...
Write a function that accepts two strings and returns the indices of all the occurrences of the second string in the first string as a list. If the second string is not present in the first string then it should return -1.
Input def indices(first, second): for i in second: if i in first: print(test1.index(i)) if i not in first: print(-1) test1 = input("Enter...
Write a program to create a list of the cubes of only the even integers appearing in the input list (may have elements of other types also) using the following: a.) ‘for’ loop b.) list comprehension
Input # a) test = [] n = int(input('enter the length of list \n')) for j in range(0, n): vals = input('enter the values: ')...
Write a program to read a file and perform the following
Write a program to read a file and a.) Print the total number of characters, words, and lines in the file. b.) Calculate the frequency of...
Write a program to define a class Point with coordinates x and y as attributes. Create relevant methods and print the objects. Also, define a method distance to calculate the distance between any two point objects.
Input class Point: def __init__(self, x, y): self.x = x self.y = y self.x1 = int(input('enter the value for x1: ')) self.y1 =...
Write a function that prints a dictionary where the keys are numbers between 1 and 5 and the values are cubes of the keys.
Input def dict_cube(): values = {'1': '', '2': '', '3': '', '4': '', '5': '', } for i in values.keys(): values.update({i: (int(i) ** 3)})...
Consider a tuple t1=(1, 2, 5, 7, 9, 2, 4, 6, 8, 10). Write a program to perform the following operations
Consider a tuple t1=(1, 2, 5, 7, 9, 2, 4, 6, 8, 10). Write a program to perform the following operations a) Print half the values of the...
Write a program to accept a name from a user. Raise and handle the appropriate exception(s) if the text entered by the user contains digits and/or special characters.
Input name = input('enter your name \n') name.split() c = 0 s = '"[@_!#$%^&*()<>?/\|}{~:]"' for i in range(len(name)): if...