0% found this document useful (0 votes)
53 views10 pages

Python Session 1 Exercise

This document contains a series of Python exercises to practice basic string manipulation and output. It includes questions about string indexing and slicing, string methods like upper(), lower(), split(), and join(), programs to compute distance and BMI from coordinates, modifying strings at given indices, swapping case, replacing characters, checking for substrings, and using print functions.

Uploaded by

pdanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views10 pages

Python Session 1 Exercise

This document contains a series of Python exercises to practice basic string manipulation and output. It includes questions about string indexing and slicing, string methods like upper(), lower(), split(), and join(), programs to compute distance and BMI from coordinates, modifying strings at given indices, swapping case, replacing characters, checking for substrings, and using print functions.

Uploaded by

pdanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Python Session 1 :

Exercise
Practice Questions?
1) What do the following expressions evaluate to?

 'Hello world!'[1]

 'Hello world!'[0:5]

 'Hello world!'[:5]

 'Hello world!'[3:]
2) What do the following expressions evaluate to?

 'Hello'.upper()

 'Hello'.upper().isupper()

 'Hello'.upper().lower()
3) What do the following expressions evaluate to?

 'Remember, remember, the fifth of November.'.split()

 '-'.join('There can be only one.'.split())


Exercise #1

 Write a Program to Compute the distance between two points given its
corresponding (x,y) co ordinates?

 Write a Program to Compute the BMI of a Person given inputs Weight (In
Kgs) and Height (in cm)
Exercise #2
 Read a given string, change the character at a given index and then print
the modified string.
 Inputs
The first accept the string . 
The next accept an integer , denoting the index location and then accept a
character  separated by a space.

Source: https://www.hackerrank.com/challenges/python-mutations/problem
Exercise #3

 You are given a string and your task is to swap cases. In other words,
convert all lowercase letters to uppercase letters and vice versa.
 Input : Accept single line containing a string .
 Output: Print the modified string .
Exercise #4

 Write a The program takes a string and replaces all occurrences of ‘a’
with ‘$’.
 Input : Accept single line containing a string .
 Output: Print the modified string .
Exercise #5

 The program takes a string and checks if a substring is present in the


given string.
 Input : Accept single line containing a string .
 Output: Print the Substring is present or not .
Exercise #6

 Print the following Sentence using print function :


Expected Output : The program printed "hello world"

You might also like