Python Exercise Lists

Python String Exercises

1. Write a python program to print the following patterns.

The output is:

       HHH    HHH
     HHH   HHH   HHH
    HHH          HHH
     HHH        HHH
      HHH      HHH
        HHH  HHH
          HHH

Click for the answer



2. Write a python program to display the sentence B after defining the variable A as shown in the following.

The output is:

variable A = ("brother", "Canada")
sentence B = I have a brother and he stays at Canada with his wife.

Click for the answer



3. Write a python program to display the sentence B after defining the variable A as shown in the following.

The output is:

variable A = ("brother", 20)
sentence B = I have a brother and he is 20 years old.

Click for the answer



4. To define the variable of name_list as in the following output. Write a python program to display the first and third name in the variable of name_list. The expected answer will be displayed in the following output too.

The output is:

name_list = ["Mark", "Nicole", "Jason", "Stephanie"]
Answer: Mark Jason

Click for the answer



5. Write a python program to request the program user to input two personal information (name and age). Then print out those program user personal information as same as the following output.

The output is:

Please input your name: Mark
Please input your age: 20
Expected Answer: Hello, Mark. You are 20 years old now. You can access to this program!

Click for the answer



6. Write a python program to print out the sentence with exactly same format as the following output.

The output is:

Expected Answer: Hello, everyone! I'm a beginner coder. Let's learn Python Programming Language together. Let me know if you need more exercises!

Click for the answer



7. Write a python program to calculate the number of days between 2018-8-8 and 2018-9-3.

The output is:

Expected Answer: The number of days between 8th Aug and 3rd September 2018: 26 days

Click for the answer



8. Write a python program to print out the names which exists in the first name list but not exist in the second set of name list as same answer in the following output.

The output is:

name_list_1= "Mark", "Nicole", "Jason", "Howard"
name_list_2= "Nicole", "Howard"
Expected Answer: The names which exists in the first name list but not exist in the second set of name list : {'Jason', 'Mark'}

Click for the answer



9. Write a python program to print out the names "Howard" has been removed from the first name list as same answer in the following output.

The output is:

name_list_1= "Mark", "Nicole", "Jason", "Howard"
Expected Answer: The names after removing Howard: {'Jason', 'Mark', 'Nicole'}

Click for the answer



10. Write a python program to change the variable_a from type of integer to string type.

The output is:

variable_a = 666
Expected Answer: The type of variable_a change from integer to: class 'str'

Click for the answer



11. Write a python program to generate the multiplication of string. The program shall allow user to input string and number of multiplications.

The output is:

string = python, number of multiplications = 3

Expected Answer:
pythonpythonpython

Click for the answer



12. Write a python program to allow user to input their weight and height in order to calculate the BMI of user. [formula of BMI = weight (kg) / height (m)]

The output is:


Please input your weight in kg: 50
Please input your height in m: 1.56

Expected Answer:
Please input your weight in kg: 50
Please input your height in m: 1.56
Your BMI is 20.55

Click for the answer



13. Write a python program to calculate the mathematics question of (a + b) * (a + b)

The output is:


a = 5
b = 8

Expected Answer:
(5 + 8) * (5 + 8) = 169

Click for the answer



14. Write a python program to calculate the distance between two defined coordinates, coordinate_1 and coordinate_2 as provided in the output below.

The output is:

coordinate_1 = [5, 1]
coordinate_2 = [8, 7]

Expected Answer:
The distance between two coordinate points is 6.708203932499369

Click for the answer



15. Write a python program to access all environment variable and a particular environment variable

The output is:

Expected Answer:
Depends on your respective environment variable

Click for the answer



16. Write a python program to calculate the total interest amount of the car loan. The borrow amount is 30,000 for 5 years with 3% interest rate.

The output is:

Borrow amount: 30 000
Years: 5
Interest rate: 3%

Expected Answer:
The total interest amount is 4500.0

Click for the answer



17. Write a python program to convert the seconds input by user into day, hour and minute.

The output is:

Please input the seconds: 43954

Expected Answer:
days:hours:minutes:seconds --> 0:12:12:34

Click for the answer



18. Write a python program to request user to input 3 random numbers therefore sort the them in increasing order without using conditional statement.

The output is:

Example:
Please input the first number: 9
Plese input the second number: 2
Please input the third number: 5

Expected Answer:
The numbers in increasing order: 2 5 9

Click for the answer



19. Write a python program to check the detail of pandas module.

The output is:

Expected Answer:
----------------------------pandas detail----------------------------
['Categorical', 'CategoricalDtype', 'CategoricalIndex', 'DataFrame', 'DateOffset', 'DatetimeIndex', 'DatetimeTZDtype', 'ExcelFile', 'ExcelWriter', 'Float64Index', 'Grouper', 'HDFStore', 'Index', 'IndexSlice', 'Int16Dtype', 'Int32Dtype', 'Int64Dtype', 'Int64Index', 'Int8Dtype', 'Interval', 'IntervalDtype', 'IntervalIndex', 'MultiIndex', 'NaT', 'Panel', 'Period', 'PeriodDtype', 'PeriodIndex', 'RangeIndex', 'Series', 'SparseArray', 'SparseDataFrame', 'SparseDtype', 'SparseSeries', 'TimeGrouper', 'Timedelta', 'TimedeltaIndex', 'Timestamp', 'UInt16Dtype', 'UInt32Dtype', 'UInt64Dtype', 'UInt64Index', 'UInt8Dtype', '__builtins__', '__cached__', '__doc__', '__docformat__', '__file__', '__git_version__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_hashtable', '_lib', '_libs', '_np_version_under1p13', '_np_version_under1p14', '_np_version_under1p15', '_np_version_under1p16', '_np_version_under1p17', '_tslib', '_version', 'api', 'array', 'arrays', 'bdate_range', 'compat', 'concat', 'core', 'crosstab', 'cut', 'date_range', 'datetime', 'describe_option', 'errors', 'eval', 'factorize', 'get_dummies', 'get_option', 'infer_freq', 'interval_range', 'io', 'isna', 'isnull', 'lreshape', 'melt', 'merge', 'merge_asof', 'merge_ordered', 'notna', 'notnull', 'np', 'offsets', 'option_context', 'options', 'pandas', 'period_range', 'pivot', 'pivot_table', 'plotting', 'qcut', 'read_clipboard', 'read_csv', 'read_excel', 'read_feather', 'read_fwf', 'read_gbq', 'read_hdf', 'read_html', 'read_json', 'read_msgpack', 'read_parquet', 'read_pickle', 'read_sas', 'read_sql', 'read_sql_query', 'read_sql_table', 'read_stata', 'read_table', 'reset_option', 'set_eng_float_format', 'set_option', 'show_versions', 'test', 'testing', 'timedelta_range', 'to_datetime', 'to_msgpack', 'to_numeric', 'to_pickle', 'to_timedelta', 'tseries', 'unique', 'util', 'value_counts', 'wide_to_long']

Click for the answer



                                                       


More Exercises:

Python String Exercises
Python List Exercises
Python Library Exercises
Python Sets Exercises
Python Array Exercises
Python Condition Statement Exercises
Python Lambda Exercises
Python Function Exercises
Python File Input Output Exercises
Python Tkinter Exercises


More Numpy Exercises:

Numpy String Exercises
Numpy Integer Exercises
Numpy Array Exercises
Numpy Data Analysis Exercises
Numpy Data Sorting Exercises


More Pandas Exercises:

Pandas Series Exercises


More Tutorials:

Python Installation - Linux (Ubuntu)
Python Installation - Mac OS
Integrated Development Environment - IDE
Python - Basic Variables
Python - Sequence Introduction
Python - Output Formatting
Python - Escape Character
Python - Type Conversion
Python - Numbers
Python – Arithmetic Operators
Python – Assignment Operators
Python – Comparison Operators
Python – Logical Operators
Python – Precedence and Associativity Operators
Python – Bytes Type and Usage
Python – Long & Raw Strings
Python – Concatenate Function
Python – Slice Function
Python – Length and Split Function
Python – Join and Count Function
Python – Find Function
Python – Index Function
Python – Alignment Function
Python – Startswith and Endswith Function
Python – String Case Conversion
Python – Remove Specified Character
Python – Encode and Decode Function
Python – dir and help Function
Python – Input Output Introduction
Python – Basic Operation
Python – Open Function
Python – Read Function
Python – Readline Function
Python – Write Function
Python – Close Function
Python – Seek and Tell Function
Python – Pickle Module
Python - File Input Module and Linecache Module
Python - Pathlib Module
Python - Pathlib Module
Python - os.path Module
Python - fnmatch Module
Python - Tuple Introduction
Python - List Introduction
Python - List Add Element
Python - List Delete Element
Python - List Modification Element
Python - List Find Element
Python - Dictionary Introduction
Python - Dictionary Basic Operation
Python - Dictionary Method Guide
Python - Set Collection
Python - Set Basic Operation
Python - Set Basic Method
Python - Frozenset Method
Python - If Condition I
Python - If Condition II
Python - While loop
Python - For loop
Python - Pass Statement
Python - Break Statement
Python - Zip Reverse Function
Python - Function Introduction
Python - Positional Parameters
Python - Key Arguments
Python - None and Return
Python - Variable Scope
Python - Local Function
Python - Closure Method
Python - Lamdba Expression