0% found this document useful (0 votes)
122 views4 pages

Exercises On Python Programming

The document contains instructions for writing Python programs to perform various tasks including: swapping variables, checking sign of a number, handling errors for invalid input, formatting strings, calculating area of shapes, reversing names, extracting file extensions, accessing list elements, calculating volume of a sphere, finding differences, indexes, and more. It also includes examples of converting between units like time, temperature, length and performing calculations on numbers.

Uploaded by

Devi Vara Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
122 views4 pages

Exercises On Python Programming

The document contains instructions for writing Python programs to perform various tasks including: swapping variables, checking sign of a number, handling errors for invalid input, formatting strings, calculating area of shapes, reversing names, extracting file extensions, accessing list elements, calculating volume of a sphere, finding differences, indexes, and more. It also includes examples of converting between units like time, temperature, length and performing calculations on numbers.

Uploaded by

Devi Vara Prasad
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 4

Write a Python program to swap two variables, using another variable

Write a Python program to swap two variables, without using any other variable

Write a Python program to check if a number is positive, negative or zero. 

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 :

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

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 volume of a sphere with radius 6.


The volume of the sphere is : V = 4/3 × π × r3 = π × d3/6.

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:

Twinkle, twinkle, little star

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 parse a string to Float or Integer.

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 calculate the hypotenuse of a right angled triangle.

Write a Python program to convert the distance (in feet) to inches, yards, and miles.

Write a Python program to convert all units of time into seconds.


Sample Input:
Input days: 4
Input hours: 5
Input minutes: 20
Input seconds: 10
Output:
The amounts of seconds 364810

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.

Write a Python program to check whether a string is numeric.

You might also like