Exercises On Python Programming
Exercises On Python Programming
Write a Python program to swap two variables, without using any other variable
Write a Python program to input a number, if it is not a number generate an error message.
Write a Python program to print the following string in a specific format (see the output).
Please use only one print function in the program.
Sample String : "Twinkle, twinkle, little star, How I wonder what you are! Up above the world
so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are"
Output :
Hint: You can make use of “\n” for newline and “\t” for tab(spaces)
Write a Python program which accepts the radius of a circle from the user and compute the
area.
Sample Output :
r = 1.1
Area = 3.8013271108436504
Write a Python program which accepts the user's first and last name and print them in reverse
order with a space between them.
Write a Python program to accept a filename from the user and print the extension of that.
Sample filename : abc.java
Output : java
Hint: Make use of split function
Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black"]
Hint: Make use of indexes
Write a Python program to get the difference between a given input number and 17
Write a Python program to get an index of “star” from a given string below:
Write a Python program that will accept the base and height of a triangle and compute the
area.
Write a Python program to accept user input and display details like name, age, address in
three different lines.
Write a Python program to solve (x + y) * (x + y).
Test Data : x = 4, y = 3
Expected Output : (4 + 3) ^ 2) = 49
Write a Python program to compute the future value of a specified principal amount, rate of
interest, and a number of years.
Test Data : amt = 10000, int = 3.5, years = 7
Expected Output : 12722.79
Write a Python program to print following Asterisks(stars) without newline or space and using
only one Asterisk(star)
*********************
Write a Python program to convert height (in feet and inches) to centimeters.
Write a Python program to convert the distance (in feet) to inches, yards, and miles.
Write a Python program to convert seconds to day, hour, minutes and seconds.
Write a Python program to calculate the sum of the digits in an 3 digit integer.
Input: 123
Output: 1+2+3=6
Write a Python program to sort three integers without using conditional statements and loops.
Sample Input:
Input first number: 2
Input second number: 4
Input third number: 5
Output:
Numbers in sorted order: 2 4 5
Write a Python program to count the number occurrence of a specific character in a string.
Hint: make use of count() function
Sample input: “This is a Test String”
Output: No of occurrences of i are 3.