Python Assignment
Python Assignment
com/python-exercises/
2.
Write a Python program to display the system version , current date and
time.
3. Write a Python program which accepts the radius of a circle from the
user and compute the area.
4. Write a Python program which accepts the user's first and last name and
print them in reverse order with a space between them.
7. Write a Python program to accept a filename from the user and print the
extension of that.
Sample filename : abc.java
Output : java
8. Write a Python program to display the first and last colors from the following
list.
color_list = ["Red","Green","White" ,"Black"]
10. Write a Python program that accepts an integer (n) and computes the
value of n+nn+nnn.
Sample value of n is 5
Expected Result : 615
11. Write a Python program to print the documents (syntax, description etc.) of
Python built-in function(s).
Sample function : abs()
Expected Result :
abs(number) -> number
Return the absolute value of the argument.
12. Write a Python program to print the calendar of a given month and year.
Note : Use 'calendar' module.
13. Write a Python program to print the following here document. Go to the
editor
Sample string :
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example
14. Write a Python program to calculate number of days between two dates.
Sample dates : (2014, 7, 2), (2014, 7, 11)
Expected output : 9 days
15. Write a Python program to get the volume of a sphere with radius 6.
16. Write a Python program to get the difference between a given number and
17, if the number is greater than 17 return double the absolute
difference.
17. Write a Python program to test whether a number is within 100 of 1000 or
2000. Go to the editor
Click me to see the sample solution
18. Write a Python program to calculate the sum of three given numbers, if the
values are equal then return thrice of their sum. Go to the editor
19. Write a Python program to get a new string from a given string where "Is"
has been added to the front. If the given string already begins with "Is" then
return the string unchanged. Go to the editor
21. Write a Python program to find whether a given number (accept from the
user) is even or odd, print out an appropriate message to the user. Go to the
editor
Click me to see the sample solution
22. Write a Python program to count the number 4 in a given list. Go to the
editor
Click me to see the sample solution
23. Write a Python program to get the n (non-negative integer) copies of the
first 2 characters of a given string. Return the n copies of the whole string if
the length is less than 2. Go to the editor
Click me to see the sample solution
24. Write a Python program to test whether a passed letter is a vowel or
not. Go to the editor
Click me to see the sample solution
27. Write a Python program to concatenate all elements in a list into a string
and return it. Go to the editor
Click me to see the sample solution
28. Write a Python program to print all even numbers from a given numbers
list in the same order and stop the printing if any numbers that come after 237
in the sequence. Go to the editor
Sample numbers list :
numbers = [
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978,
328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866,
950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379,
843, 831, 445, 742, 717,
958,743, 527
]
Click me to see the sample solution
29. Write a Python program to print out a set containing all the colors from
color_list_1 which are not present in color_list_2. Go to the editor
Test Data :
color_list_1 = set(["White", "Black", "Red"])
color_list_2 = set(["Red", "Green"])
Expected Output :
{'Black', 'White'}
Click me to see the sample solution
30. Write a Python program that will accept the base and height of a triangle
and compute the area. Go to the editor
Click me to see the sample solution
31. Write a Python program to compute the greatest common divisor (GCD) of
two positive integers. Go to the editor
Click me to see the sample solution
32. Write a Python program to get the least common multiple (LCM) of two
positive integers. Go to the editor
Click me to see the sample solution
33. Write a Python program to sum of three given integers. However, if two
values are equal sum will be zero. Go to the editor
Click me to see the sample solution
34. Write a Python program to sum of two given integers. However, if the sum
is between 15 to 20 it will return 20. Go to the editor
Click me to see the sample solution
35. Write a Python program that will return true if the two given integer values
are equal or their sum or difference is 5. Go to the editor
Click me to see the sample solution
36. Write a Python program to add two objects if both objects are an integer
type. Go to the editor
Click me to see the sample solution
37. Write a Python program to display your details like name, age, address in
three different lines. Go to the editor
Click me to see the sample solution
40. Write a Python program to compute the distance between the points (x1,
y1) and (x2, y2). Go to the editor
Click me to see the sample solution
41. Write a Python program to check whether a file exists. Go to the editor
Click me to see the sample solution
46. Write a python program to get the path and name of the file that is
currently executing. Go to the editor
Click me to see the sample solution
47. Write a Python program to find out the number of CPUs using. Go to the
editor
Click me to see the sample solution
49. Write a Python program to list all files in a directory in Python. Go to the
editor
Click me to see the sample solution
50. Write a Python program to print without newline or space. Go to the editor
Click me to see the sample solution
54. Write a Python program to get the current username Go to the editor
Click me to see the sample solution
55. Write a Python to find local IP addresses using Python's stdlib Go to the
editor
Click me to see the sample solution
56. Write a Python program to get height and width of the console window. Go
to the editor
Click me to see the sample solution
57. Write a program to get execution time for a Python method. Go to the
editor
Click me to see the sample solution
58. Write a python program to sum of the first n positive integers. Go to the
editor
Click me to see the sample solution
59. Write a Python program to convert height (in feet and inches) to
centimeters. Go to the editor
Click me to see the sample solution
62. Write a Python program to convert all units of time into seconds. Go to the
editor
Click me to see the sample solution
63. Write a Python program to get an absolute file path. Go to the editor
Click me to see the sample solution
65. Write a Python program to convert seconds to day, hour, minutes and
seconds. Go to the editor
Click me to see the sample solution
66. Write a Python program to calculate body mass index. Go to the editor
Click me to see the sample solution
68. Write a Python program to calculate the sum of the digits in an integer. Go
to the editor
Click me to see the sample solution
69. Write a Python program to sort three integers without using conditional
statements and loops. Go to the editor
Click me to see the sample solution
75. Write a Python program to get the copyright information. Go to the editor
Click me to see the sample solution
76. Write a Python program to get the command-line arguments (name of the
script, the number of arguments, arguments) passed to a script. Go to the
editor
Click me to see the sample solution
78. Write a Python program to find the available built-in modules. Go to the
editor
Click me to see the sample solution
79. Write a Python program to get the size of an object in bytes. Go to the
editor
Click me to see the sample solution
80. Write a Python program to get the current value of the recursion limit. Go
to the editor
Click me to see the sample solution
82. Write a Python program to calculate the sum over a container. Go to the
editor
Click me to see the sample solution
83. Write a Python program to test whether all numbers of a list is greater than
a certain number. Go to the editor
Click me to see the sample solution
86. Write a Python program to get the ASCII value of a character. Go to the
editor
Click me to see the sample solution
87. Write a Python program to get the size of a file. Go to the editor
Click me to see the sample solution
88. Given variables x=30 and y=20, write a Python program to print t
"30+20=50". Go to the editor
Click me to see the sample solution
90. Write a Python program to create a copy of its own source code. Go to the
editor
Click me to see the sample solution
93. Write a Python program to get the identity of an object. Go to the editor
Click me to see the sample solution
94. Write a Python program to convert a byte string to a list of integers. Go to
the editor
Click me to see the sample solution
96. Write a Python program to print the current call stack. Go to the editor
Click me to see the sample solution
97. Write a Python program to list the special variables used within the
language. Go to the editor
Click me to see the sample solution
98. Write a Python program to get the system time. Go to the editor
99. Write a Python program to clear the screen or terminal. Go to the editor
Click me to see the sample solution
100. Write a Python program to get the name of the host on which the routine
is running. Go to the editor
Click me to see the sample solution
101. Write a Python program to access and print a URL's content to the
console. Go to the editor
Click me to see the sample solution
102. Write a Python program to get system command output. Go to the editor
Click me to see the sample solution
103. Write a Python program to extract the filename from a given path. Go to
the editor
Click me to see the sample solution
104. Write a Python program to get the effective group id, effective user id,
real group id, a list of supplemental group ids associated with the current
process. Go to the editor
Note: Availability: Unix.
Click me to see the sample solution
105. Write a Python program to get the users environment. Go to the editor
Click me to see the sample solution
108. Write a Python program to find path refers to a file or directory when you
encounter a path name. Go to the editor
Click me to see the sample solution
110. Write a Python program to get numbers divisible by fifteen from a list
using an anonymous function. Go to the editor
Click me to see the sample solution
111. Write a Python program to make file lists from current directory using a
wildcard. Go to the editor
Click me to see the sample solution
112. Write a Python program to remove the first item from a specified list. Go
to the editor
Click me to see the sample solution
114. Write a Python program to filter the positive numbers from a list. Go to
the editor
Click me to see the sample solution
115. Write a Python program to compute the product of a list of integers
(without using for loop). Go to the editor
Click me to see the sample solution
117. Write a Python program to prove that two string variables of same value
point same memory location. Go to the editor
Click me to see the sample solution
118. Write a Python program to create a bytearray from a list. Go to the editor
Click me to see the sample solution
120. Write a Python program to format a specified string to limit the number of
characters to 6. Go to the editor
Click me to see the sample solution
123. Write a Python program to determine the largest and smallest integers,
longs, floats. Go to the editor
Click me to see the sample solution
124. Write a Python program to check if multiple variables have the same
value. Go to the editor
Click me to see the sample solution
126. Write a Python program to get the actual module object for a given
object. Go to the editor
Click me to see the sample solution
131. Write a Python program to split a variable length string into variables. Go
to the editor
Click me to see the sample solution
132. Write a Python program to list home directory without absolute path. Go
to the editor
Click me to see the sample solution
133. Write a Python program to calculate the time runs (difference between
start and current time) of a program. Go to the editor
Click me to see the sample solution
134. Write a Python program to input two integers in a single line. Go to the
editor
Click me to see the sample solution
136. Write a Python program to find files and skip directories of a given
directory. Go to the editor
Click me to see the sample solution
142. Write a Python program to find the operating system name, platform and
platform release date. Go to the editor
Operating system name:
posix
Platform name:
Linux
Platform release:
4.4.0-47-generic
Click me to see the sample solution
148. Write a Python function to find the maximum and minimum numbers from
a sequence of numbers. Go to the editor
Note: Do not use built-in functions.
Click me to see the sample solution
149. Write a Python function that takes a positive integer and returns the sum
of the cube of all the positive integers smaller than the specified number. Go
to the editor
Click me to see the sample solution
150. Write a Python function to find a distinct pair of numbers whose product
is odd from a sequence of integer values. Go to the editor
Click me to see the sample solution